Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Buttons in a Relative layout don't trigger "Clicked" events

$
0
0

I'm a newbie, using XAML with Xamarin Forms.
Here's the UI:

UI

And here's the code:

    <RelativeLayout x:Name="DeviceLayout" VerticalOptions="Center" HorizontalOptions="Center">

    <RelativeLayout.WidthRequest>
        ...
    </RelativeLayout.WidthRequest>

    <RelativeLayout.HeightRequest>
        ....
    </RelativeLayout.HeightRequest>

    <RelativeLayout VerticalOptions="Fill" HorizontalOptions="Fill">
        <Button x:Name="1" Clicked="OnClickCommand"
        RelativeLayout.XConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=110}"
        RelativeLayout.YConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=5}"
        BackgroundColor="Gray"
        WidthRequest="30"
        HeightRequest="30"
        />
        <Button  x:Name="2" Clicked="OnClickCommand"
        RelativeLayout.XConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=185}"
        RelativeLayout.YConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=35}"
        BackgroundColor="Purple"
        WidthRequest="30"
        HeightRequest="30"
        />

        <Button  x:Name="3" Clicked="OnClickCommand"
        RelativeLayout.XConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=215}"
        RelativeLayout.YConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=115}"
        BackgroundColor="Green"
        WidthRequest="30"
        HeightRequest="30"
        />

        <Button  x:Name="4" Clicked="OnClickCommand"
        RelativeLayout.XConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=185}"
        RelativeLayout.YConstraint=
                 "{ConstraintExpression Type=Constant, 
                                        Constant=185}"
        BackgroundColor="Yellow"
        WidthRequest="30"
        HeightRequest="30"
        />
        ....
    </RelativeLayout>

And here's my OnClickCommand method:

    public void OnClickCommand (object sender, EventArgs e) {
        var button = (Button)sender;
        Console.WriteLine ("Clicked!");
    }

The 'Clicked' event is not triggered only for the purple, green and yellow buttons (i.e. the buttons in the left hemisphere of the UI shown above).
Is this a bug or is there something wrong with my XAML layout?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>