简体   繁体   中英

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") 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM