简体   繁体   中英

How do you make a Xamarin.Forms Switch Invisible?

I have a basic ListView of items in my app that has a switch attached to it. My item class has a bool canChange attribute. I want to bind the switch's visibility to the value of the canChange bool. Therefore, if canChange == true, the switch will be visible, but if canChange == false, the switch will be invisible.

Here is my Item Class:

public class Item
{
    public string name { get; set;}
    public bool canClaim { get; set;}
}

Here is my current XAML:

<ListView.ItemTemplate>
<DataTemplate>
  <ViewCell>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Label Text="{Binding name}" Grid.Column="0"/>
      <Switch Grid.Column="1" IsVissible="{Binding canChange}"/>
    </Grid>
  </ViewCell>
</DataTemplate>

Right now I know that my App crashes becasue the "IsVissible" property doesn't exist, but is there another property or way to make the switch dissappear? Another possible solution is for it to change to a lighter color so the user can recognize that the switch can't be toggled, although I don't know how to do that either.

make the switch dissappear

Maybe you meant IsVisible instead of IsVissible ?

the switch can't be toggled

The property IsEnabled should be the right thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM