Reputation: 181
<StackPanel Grid.Column="0" >
<ToggleButton Name="buttonEditListBoxItem"
Content="Edit"
IsChecked="False"
Click="buttonEditListBoxItem_Click"></ToggleButton>
<ListBox Name="ListBoxTriggers"
SelectedValuePath="TriggerId"
IsSynchronizedWithCurrentItem="True"
SelectionChanged="Triggers_SelectionChanged"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate> <Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="AUTO"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox Visibility="{Binding ElementName=buttonEditListBoxItem, Path=IsChecked, Converter={StaticResource visibilityConverter}}" Grid.Column="0" VerticalAlignment="Center" x:Name="checkBoxTriggers" ></CheckBox>
<Button Grid.Column="1" Style="{StaticResource GlassButton}"
Uid="{Binding Path=TriggerId}"
Margin="5"
x:Name="ButtonTrigger"
GotFocus="ButtonTrigger_GotFocus"
>
<Button.Content>
<TextBlock Foreground="White" TextAlignment="Justify"
TextWrapping="Wrap" Margin="6" Text="{Binding Path=Name}"/>
</Button.Content>
</Button>
</Grid>
</DataTemplate> </ListBox.ItemTemplate>
</ListBox>
I have a data template for a Listbox which has a button and a checkbox .There is a ToggleButton outside the listbox which decides the visbility of the checkboxes. The problem is if i have clicked on the ToggleButton and the checkboxes are visible and i have checked some checkboxes when i click the ToggleButton again the checkboxes are hidden but I want the checkboxes to reset; as in when they are visible again i want none of the checkboxes clicked.
Upvotes: 1
Views: 1279
Reputation: 2475
You can add a handler for the IsVisibleChanged event of the CheckBox:
IsVisibleChanged="checkBoxTriggers_IsVisibleChanged"
and in the handles clear the IsChecked flag:
private void checkBoxTriggers_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
CheckBox cb = sender as CheckBox;
if (!cb.IsVisible)
cb.IsChecked = false;
}
Probably same effect could be achieved by using a trigger similar to this:
<Trigger Property="IsVisible" Value="false">
<Setter Property="IsChecked" Value="false" />
</Trigger>
Upvotes: 2