Hello All,
I am facing an strange behavior in Xamarin.forms.
When i m writting below xaml code it's working fine as expected but the same thing i m trying to achieve dynamically from code behind event for button is not getting fired.
XAML code:
<AbsoluteLayout>
<Button x:Name="firstChild" Text="First Child"></Button>
<AbsoluteLayout Padding="70">
<Label Text="inner child"></Label>
</AbsoluteLayout>
</AbsoluteLayout>
Below is my .cs code which is trying to achieve the same thing but event is not getting fired.
public partial class TestPage : ContentPage
{
MR.Gestures.AbsoluteLayout mainLayout = new MR.Gestures.AbsoluteLayout ();
Button firstChild = new Button {
Text = "First Child",
TextColor = Color.White,
BackgroundColor = Color.Red
};
MR.Gestures.AbsoluteLayout innerLayout = new MR.Gestures.AbsoluteLayout {Padding=70};
Label innerLabel=new Label{
Text="inner child",
TextColor=Color.Red
};
public TestPage ()
{
InitializeComponent ();
firstChild.Clicked += btnclick;
mainLayout.Children.Add (firstChild);
innerLayout .Children.Add (innerLabel);
mainLayout.Children.Add (innerLayout );
this.Content = mainLayout;
}
void btnclick(object sender,EventArgs args)
{
DisplayAlert ("Hello", "Hello World", "OK");
}
}