Reputation: 697
Can this be done? What I am after is something like this:
<StackLayout x:Name="AParent">
<StackLayout>
<Button Text="Click me!" Clicked="AParent.OnButtonClicked()" />
</StackLayout>
</StackLayout>
and in the codebehind for AParent:
async void OnButtonClicked(object sender, EventArgs e)
{
Debug.WriteLine("Click!");
}
Upvotes: 1
Views: 774
Reputation: 34083
I'm not sure if I understand you correctly, but I think what you're after is this. Specify your Button
like this:
<Button Text="Click me!" Clicked="OnButtonClicked" />
And in your code-behind you can do this:
void OnButtonClicked(object sender, EventArgs e)
{
Debug.WriteLine("Click!");
}
It doesn't matter that the Button
is nested inside other elements. These are not parent classes, but simply parents in the visual tree. All the objects are still in the same class and can be reached through the code-behind of that page.
Upvotes: 1