I am trying to design an application with 256 button inside. These buttons are added by using "for" loop in c#, so they are not in the XAML code. My problem is that - I don't know how to add a Context Menu to such a button. The context menu should open when clicking right mouse button on particular button. Then I want to be able to change some variable in code, when selecting some of the context menu item.
My code for adding buttons is following:
public MainWindow()
{
InitializeComponent();
int num = number(3);
for(int i =0; i<(num*num); i++)
{
//i want initialize the context menu here
Button button = new Button();
button.Name = "Butt" + counter;
button.Content = "New";
counter++;
button.Height = 35;
button.Width = 35;
button.Click += new RoutedEventHandler(NewButton_Click);
wp.Children.Add(button); // Wrap Panel where buttons displayed
}}