に伴う問題は、私は、トリガを有する2つのリストビューを有するよう選択された変更に濃い灰色の背景色と白の前景色。 問題は、最初のリストビューでアイテムを選択した後、2番目のリストビューでアイテムを選択すると、最初のリストビューのフォアグラウンドのアイテムが再び黒くならず、白く保たれるということです。WPF - トリガー
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="190*" />
<RowDefinition Height="121*" />
</Grid.RowDefinitions>
<Grid.Resources>
<ResourceDictionary>
<Style x:Key="@ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType='{x:Type ListViewItem}'>
<Grid SnapsToDevicePixels="True" Margin="0">
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<GridViewRowPresenter x:Name="Content" TextBlock.Foreground="{TemplateBinding Foreground}"
Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="TextElement.Foreground" Value="White" TargetName="Content" />
<Setter Property="Background" Value="DarkGray" TargetName="Bd"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
<Condition Property="Selector.IsSelectionActive" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="@TextCellTemplate">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
<DataTemplate x:Key="@TrubleCellTemplate">
<Rectangle Width="20" Height="20" Fill="Black"></Rectangle>
</DataTemplate>
</ResourceDictionary>
</Grid.Resources>
<ListView ItemsSource="{Binding Persons}" Style="{DynamicResource @ListView}" ItemContainerStyle="{DynamicResource @ListViewItemStyle}">
<ListView.View>
<GridView>
<GridViewColumn Width="40" CellTemplate="{DynamicResource @TextCellTemplate}" />
<GridViewColumn Width="131" CellTemplate="{DynamicResource @TrubleCellTemplate}" />
</GridView>
</ListView.View>
</ListView>
<ListView ItemsSource="{Binding Persons}" Style="{DynamicResource @ListView}" ItemContainerStyle="{DynamicResource @ListViewItemStyle}" Grid.Row="1">
<ListView.View>
<GridView>
<GridViewColumn Width="40" CellTemplate="{DynamicResource @TextCellTemplate}" />
<GridViewColumn Width="131" CellTemplate="{DynamicResource @TrubleCellTemplate}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
ちょうど予感が...参照してください。 – Gishu
@ Gishu - ありがとうございましたが、動作しませんでした – Erez
@Erez - Ok。逆方向トリガを追加してください。つまり、IsSelected = "False"の場合、またはスタイル自体にデフォルトの状態を指定してください。彼らは動作しないときのトリガーは非常に迷惑することができます - 私は最近、1に直面 - このスルー読んで、あなたはどんなリードを取得するかどうかを確認http://geekswithblogs.net/thibbard/archive/2008/05/13/wpf---changing -the-of-a-togglebutton-when-checked.aspx – Gishu