Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a button programmatically in Windows Phone 7 (WP7)

I am trying to create a Button in Windows phone 7 without making use of the .xaml file. I was able to create a 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;

This works fine. But how do I listen to the click event of this button. If it was created using the .xaml file, the listener function would have been created automatically when double-clicked on the button in the preview window. How can I create it in this case.

Be advised, I am a newbie in WP7 programming. Thanks!

like image 844
ChethanRao Avatar asked Jul 18 '11 05:07

ChethanRao


1 Answers

btn.Click += ... (after the += you can push tab twice to add an event handler).

like image 72
hcb Avatar answered Sep 30 '22 13:09

hcb