Xaml Forms Event not Raised on Modal Dialog

AndrewPriceAndrewPrice USMember
edited August 2016 in Xamarin.Forms

<StackLayout> <Button Text="Take a Picture" Command="{Binding TakePicture}" /> <Button Text="Load From Gallery" Command="{Binding SelectPicture}" /> <Image Source="{Binding Picture}"/> </StackLayout>

In the code behind I have

public CameraPage() { InitializeComponent(); BindingContext = new PictureViewModel(DependencyService.Get<ICameraProvider>()); }
It works fine like this, but what I am attempting to do is construct this in code behind using a custom function, I cannot get it working, what am I missing ? The event buttons do not raise the event when the code is run on a modal page ?

    `public StackLayout AddImageControl()
    {
        StackLayout qLayout = new StackLayout()
        {
            Orientation = StackOrientation.Horizontal
        };
        qLayout.BindingContext = 
                new PictureViewModel(DependencyService.Get<ICameraProvider>());

        Image img = new Image()
                {
                    WidthRequest = 200,
                    HorizontalOptions = LayoutOptions.End,
                    Source = ((PictureViewModel)qLayout.BindingContext).Picture
                };

        Button btnTakePicture = new Button()
                {
                    Text = "Take a Picture",
                    Command = ((PictureViewModel)qLayout.BindingContext).TakePicture
                };
                Button btnSelectPicture = new Button()
                {
                    Text = "SelectPicture",
                    Command = ((PictureViewModel)qLayout.BindingContext).SelectPicture
                };

        qLayout.Children.Add(img);
        qLayout.Children.Add(btnTakePicture);
        qLayout.Children.Add(btnSelectPicture);

        return qLayout;
  }`

XAmL of Page

  '<ContentPage.Content>
       <StackLayout Orientation="Vertical" BackgroundColor="#E3E3E3"  HorizontalOptions="FillAndExpand" Margin="10,50,10,0">
           <Label x:Name="lblFormTitle"></Label>
           <StackLayout x:Name="FormOptions" VerticalOptions="FillAndExpand"
                    HorizontalOptions="FillAndExpand"
                    Orientation="Vertical"
                    Spacing="15"></StackLayout>
           <StackLayout Orientation="Horizontal" BackgroundColor="#E3E3E3"  HorizontalOptions="FillAndExpand" Margin="10,50,10,0">
             <Button Clicked="ButtonLeft_Clicked" x:Name="ButtonLeft" Text="OK"></Button>
             <Button Clicked="ButtonRight_Clicked"   x:Name="ButtonRight" Text="Cancel"></Button>
        </StackLayout>
    </StackLayout>
</ContentPage.Content>'

Then in the code behind we have

        `FormOptions.Children.Add(ImageControl.AddImageControl());`
Sign In or Register to comment.