How to create a custom control using buttons and how to add event events events events in silverlight for Windows Mobile 7

as I follow the link to create a 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 a button to a user control and add an event handler for the click event in this?

I added a click event using the following code snippet `

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 go to some page after clicking the buttons.

how to do it??? I do not get the parameter "NavigationService.Navigate" in the button click event.

thanx in advance. :)

+3
1

XAML, Button OnApplyTemplate(), Click.

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

All Articles