jeudi 9 janvier 2020

Trying to hide a checkbox until a menu option is selected, but checkbox won't hide

I have a checkbox that should only appear when a menu option is selected. When the menu option is not selected, the checkbox should be hidden. I have a visibility variable setup in the code:

private Visibility _checkboxVisibility;
public Visibility CheckboxVisibility 
{ 
    get 
    { 
        return _checkboxVisibility; 
    } 
    set 
    { 
        SetProperty(ref _checkboxVisibility, value);
        OnPropertyChanged(nameof(CheckboxVisibility));
    } 
}

When I initialize the view model I make sure that this is set to Hidden. It is set to Visible when the menu option is selected.

Here is a snippet of the XAML code:

<ListView.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="7*" />
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="2*" />
            </Grid.ColumnDefinitions>
            <CheckBox Grid.Column="0"
                      IsChecked="{Binding IsSelected, Mode=TwoWay}"
                      Visibility="{Binding CheckboxVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

There are more columns but this seems like the important bit. If i set it to straight Hidden, the checkbox will be hidden, so there is something wrong with my binding, but I'm not sure what. I've tried also binding it to a Boolean and using a converter, but that didn't seem to help either. I've tried looking for an answer online, but everywhere I go I get binding visibility of another item to a checkbox. Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire