Creating a button programmatically in Windows Phone 7 (WP7)

I am trying to create a button on a Windows 7 phone without using a .xaml file. I was able to create the button programmatically as follows:

                Button btn = new Button() { Content = "Button" }; 
                btn.Width = 148;
                btn.Height = 148;
                Thickness margin = new Thickness(x, y, x1, 400);
                btn.Margin = margin;

It works great. But how can I listen to the click event of this button. If it was created using the .xaml file, the listener function would be created automatically by double-clicking the button in the preview window. How can I create it in this case.

Be careful, I'm new to WP7 programming. Thank!

+5
source share
1 answer

btn.Click +=... (after + = you can double-click a tab to add an event handler).

+9
source

All Articles