Xlabs Checkbox Checked one or the other

jenova1628jenova1628 Member ✭✭✭

Hi I am trying to make 2 checkboxes using Xlabs Forms and make the user choose one of the other. Can anybody help me with this below is what i currently have.

MainPage.xaml:

<controls:CheckBox x:Name="Outgoing" DefaultText="Outgoing Product"/> <controls:CheckBox x:Name="Incoming" DefaultText="Incoming Product"/>

MainPage.xaml.cs:

`if (Outgoing.Checked == true)
  {
    Incoming.Checked = false;
   }
 if (Incoming.Checked == true)
  {
    Outgoing.Checked = false;
  }`

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @jenova1628 - Are you happy to have a default value when the page is first populated? If so, why not just have one CheckBox, or one Switch, or two RadioButtons in a group?

    If you don't want a default value, separate our the two tests that you have in your code so that

    if (Outgoing.Checked == true)
    {
        Incoming.Checked = false;
    }
    

    is only called when Outgoing.Checked changes

    and

    if (Incoming.Checked == true)
    {
        Outgoing.Checked = false;
    }
    

    is only called when Incoming.Checked changes

  • jenova1628jenova1628 Member ✭✭✭

    is only called when Outgoing.Checked changes

    This is what I am currently doing I believe in the public MainPage() there is two if statements like I show above

  • JohnHardmanJohnHardman GBUniversity mod

    @jenova1628 said:

    is only called when Outgoing.Checked changes

    This is what I am currently doing I believe in the public MainPage() there is two if statements like I show above

    Post the methods in their entirety, rather than just a snippet. Also, show how those methods are wired to the XAML so that we can see how they are called (assuming they are - have you put a breakpoint in them to check?)

Sign In or Register to comment.