Trevor M
Trevor M

Reputation: 157

BooleanToVisibilityConverter with checkbox

I am trying to hide the grid, controlled by the checkbox. Currently, when I use the box nothing happens. I cannot figure out why. Everything I have found online is exactly what I have.

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="BoolToVis"/>
</Window.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <!--upper window..-->
    <CheckBox x:Name="show" Grid.Row="1" IsChecked="False">Display Preview with Sliders?</CheckBox>
    <Grid Grid.Row="1" 
          Visibility="{Binding ElementName=show, Path=isChecked, Converter={StaticResource BoolToVis}}">
        <!--what I want to hide-->
    </Grid>
</Grid>

It doesn't make any sense.

Upvotes: 2

Views: 4950

Answers (3)

Claw
Claw

Reputation: 474

I advice to use a DataTrigger

 <Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBoxStyle}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding ElementName=show,Path=IsChecked,}" Value="False">
            <Setter Property="Visibility" Value="Collapsed"></Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>

Upvotes: 2

Rohit Vats
Rohit Vats

Reputation: 81253

Property names are case sensitive. Replace isChecked with IsChecked in your binding.

Visibility="{Binding ElementName=show, Path=IsChecked,
                     Converter={StaticResource BoolToVis}}"

Upvotes: 4

nvoigt
nvoigt

Reputation: 77304

Try

Path=IsChecked

Even XAML is case-sensitive.

Upvotes: 2

Related Questions