开发者

Creating a button programmatically in Windows Phone 7 (WP7)

开发者 https://www.devze.com 2023-03-20 19:24 出处:网络
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 :

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.Mar开发者_JAVA百科gin = 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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消