2011-02-26 59 views
1
<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> 

我對其中有一個按鈕和一個複選框。有一個列表框數據模板是決定複選框的visbility列表框外的切換按鈕。 問題是如果我點擊了ToggleButton並且複選框是可見的,並且當我再次單擊ToggleButton時我檢查了一些複選框,但複選框已隱藏,但我希望複選框重置;就像在他們再次可見時一樣,我不想點擊任何複選框。如何重置複選框的財產器isChecked中的DataTemplate一個列表框

回答

2

您可以添加一個處理CheckBox的IsVisibleChanged在事件:

IsVisibleChanged="checkBoxTriggers_IsVisibleChanged" 

,並在手柄清除器isChecked標誌:

private void checkBoxTriggers_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) 
{ 
    CheckBox cb = sender as CheckBox; 

    if (!cb.IsVisible) 
    cb.IsChecked = false; 
} 

大概相同的效果,可以實現通過使用觸發器類似於此:

<Trigger Property="IsVisible" Value="false"> 
    <Setter Property="IsChecked" Value="false" /> 
</Trigger> 
相關問題