I'm creating a custom control for windows 10. I know that I can attach events to the TemplateChildren by using GetTemplateChild("Button") and then I can assign a method for example to the Tapped Event.
Now I want to assign an Method to an event outside the Control .cs class. In Mainpage.xaml I can assign e.g. a Method to the Tapped event like this: <local:MyControl Tapped="New_Hanlder"><local:MyControl>.
But how can I assign a method to a child of that control and not to the whole? Like for example I got a custom control with a grid and an Button, how can I only handle the Button Click Event in the Mainpage.xaml.cs file and NOT in the control file?
I tried this in my Control .cs class:
AppBarButton b;
In the method which is loaded when the Control is loaded:
b = GetTemplateChild("Go") as AppBarButton;
And then I got this public method:
public AppBarButton getAppBarButton()
{
retu b;
}
But accessing the AppBarButton is throwing an Exception.
Please help me to get this working. Thanks in regard!
