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

Switch Toggled IsToggled Issue.

$
0
0

Good afternoon, I am very new to Xamarin. I have a problem and I don't know how to solve it.

I have a switch control

<Switch IsToggled="{Binding IsSelected}" Toggled="OnToggledEvent" Margin="0,0,40,0" Grid.Row="0" Grid.Column="2" />

when I use the PICKER CHANGE event, I load the user permissions and the switch goes on or off

but when the switch move it automatically activates the event Toggled="OnToggledEvent"
that with that event, I grant or remove permissions.

So what happens when I choose a user from the picker, first load their permissions and when moving the switch to the on or off state, it triggers the event Toggled="OnToggledEvent"

How can I make Toggled = "OnToggledEvent" only activate when I press the switch and not when it moves with the picker?

` public class PermisosGenerales : INotifyPropertyChanged
{

    public string id { get; set; }
    public string Pagina { get; set; }

    public string Modulo { get; set; }
    public string Acceso { get; set; }


    private bool isSelected;
    public bool IsSelected
    {
        get { return isSelected; }
        set
        {
            isSelected = value;
         OnPropertyChanged(nameof(IsSelected));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string Acceso)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Acceso));
    }


}`

PICKER CHANGED LOAD SWITCH

` private void FillPicker1()

           var selectedValue = PickerEstados.Items[PickerEstados.SelectedIndex];
            var uri = "Usuario?usuario=" + selectedValue;
            var request = new HttpRequestMessage();
            request.RequestUri = new Uri(uri);
            var client = new HttpClient();
            HttpResponseMessage response = await client.SendAsync(request);
            HttpContent content = response.Content;
            var json = await content.ReadAsStringAsync();
            var result = JsonConvert.DeserializeObject<List<PermisosGenerales>>(json);


            List<PermisosGenerales> itemSource = result.ToList();
            foreach (PermisosGenerales item1 in itemSource)
            {
                if (item1.Acceso == "SI")
                {
                    item1.IsSelected = true;
                }
                else
                {
                    item1.IsSelected = false;
                }
            }`

Viewing all articles
Browse latest Browse all 91519

Trending Articles



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