开发者

How to create custom control with buttons and how to add event button click event in silverlight for windows mobile 7

as i am following link for creating custom control for my application. http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps

can anyone tell me how to add button in custom control and add event handler for click event in that?

I added click event using following piece of code `

public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            Button btn1, btn2, btn3, btn4;

            btn1 = GetTemplateChild("MyButton1") as Button;
            btn1.Click += new RoutedEventHandler(btn1_Click);
            btn2 = GetTemplateChild("MyButton2") as Button;
            btn2.Click += new RoutedEventHandler(btn2_Click);
            btn3 = GetTemplateChild("MyButton3") as Button;
            btn3.Click += new RoutedEventHandler(btn3_Click);
            btn4 = GetTemplateChild("MyButton4"开发者_C百科) as Button;
            btn4.Click += new RoutedEventHandler(btn4_Click);
        }`

Now if i want to navigate to some page after clicking buttons.

how to do that?? I am not getting "NavigationService.Navigate" option in button click event.

thanx in advance. :)


Once you added the Button in to the XAML, access the Button instance inside the OnApplyTemplate() method and then subscribe the Click event handler.

Button btn = this.GetTemplateChild("myButton") as Button;
btn.Click += new RoutedEventHandler(_btn_Click);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜