Xamarin Switch

KonoDioDaKonoDioDa USMember ✭✭

Hello again everyone, So I have a two labels in my .xaml.

in my .cs all they output is

Tracer.Text = "Tracer is best!";
Widowmaker.Text = "Widow is best!";

I would like to use a switch to be able to switch between them, but all I can get my switch to do is say "True" and "False" I have no idea how to implement the labels to each side.

here is the switch code I'm using so far

.cs

private void switcher_Toggled(object sender, ToggledEventArgs e)
{
bool isToggled = e.Value;

       Tracer.Text = isToggled.ToString();
       Widowmaker.Text = isToggled.ToString();


    }

I would like the left side to say Tracer is best while on the right it says Widow is best, so what would be my best course of action here?

Best Answer

Answers

  • MohamedCHOUCHANEMohamedCHOUCHANE FRMember ✭✭

    Hi,

    You can try this :

    private void switcher_Toggled(object sender, ToggledEventArgs e)
    {
        bool isToggled = e.Value;
        Tracer.Text = isToggled ? "Tracer is best!" : "Widow is best!";
           Widowmaker.Text = isToggled ? "Widow is best!" : "Tracer is best!";
    }
    
  • KonoDioDaKonoDioDa USMember ✭✭

    @MohamedCHOUCHANE said:
    Hi,

    You can try this :

    private void switcher_Toggled(object sender, ToggledEventArgs e)
    {
      bool isToggled = e.Value;
      Tracer.Text = isToggled ? "Tracer is best!" : "Widow is best!";
           Widowmaker.Text = isToggled ? "Widow is best!" : "Tracer is best!";
    }
    

    I feel like this is starting to go in the right track but the problem with that is my text I have stored is not being put out, its just being replaced, I'm wanting the text to appear by itself.

  • KonoDioDaKonoDioDa USMember ✭✭

    @MohamedCHOUCHANE said:
    Sorry, I did not undestand

    private void switcher_Toggled(object sender, ToggledEventArgs e)
    {
      bool isToggled = e.Value;
      Tracer.IsEnabled = isToggled;
           Widowmaker.IsEnabled = !isToggled;
    }
    

    That works perfect! Thank you so much.

Sign In or Register to comment.