두 개의 ListView를 사용하여 배경색을 진한 회색으로 변경하고 전경색을 흰색으로 변경했습니다. 문제는 첫 번째 목록보기에서 항목을 선택한 다음 두 번째 목록보기의 항목을 선택하면 첫 번째 목록보기 전경의 항목이 다시 검은 색으로 나타나지 않고 흰색으로 유지된다는 것입니다.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>
ResourceDictionary의 스타일 정의 (요소)에'x : Shared = "false"를 추가하면 문제가 해결되는지 확인하십시오. – Gishu
@ Gishu - 감사하지만 작동하지 않았습니다. – Erez
@Erez - Ok. 역방향 트리거를 추가하십시오. 즉, IsSelected = "False"이거나 스타일 자체에 기본 상태를 지정하십시오. 방아쇠는 작동하지 않을 때 매우 성가시다. 최근에 직면했다. 이것을 통해 읽고 리드가 있는지 확인한다. http://geekswithblogs.net/thibbard/archive/2008/05/13/wpf---changing -the-to-a-togglebutton-when-checked.aspx – Gishu