Не срабатывают триггеры у ListBox
Пытаюсь отключить выделение ListBoxItem'ов. Переопределил стиль двух триггеров, но при наведении и выделении ListBoxItem'a они все равно срабатывают.
XAML:
<ListBox ItemsSource="{Binding Winners}">
<ListBox.Template>
<ControlTemplate>
<Border BorderThickness="1" BorderBrush="Black" CornerRadius="8">
<DockPanel>
<Grid DockPanel.Dock="Top">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="Угадавшие участники игры:"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
BorderThickness="0, 0, 0, 1"
BorderBrush="Black"
Padding="0"/>
</Grid>
<ScrollViewer>
<ItemsPresenter SnapsToDevicePixels="True"/>
</ScrollViewer>
</DockPanel>
</Border>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="BorderThickness" Value="0, 0, 0, 1"/>
<Setter Property="BorderBrush" Value="Black"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0, 0, 0, 1"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0, 0, 0, 1"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding StdWin}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Ответы (1 шт):
Автор решения: aepot
→ Ссылка
Если нужно совсем отключить выделение, то лучше использовать ItemsControl вместо ListBox.
<ItemsControl Grid.Row="1" ItemsSource="{Binding Winners}">
<ItemsControl.Template>
<ControlTemplate>
<Border BorderThickness="1" BorderBrush="Black" CornerRadius="8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="LightGray" CornerRadius="8,8,0,0" Padding="3">
<TextBlock Text="Угадавшие участники игры:" HorizontalAlignment="Center" />
</Border>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<ItemsPresenter SnapsToDevicePixels="True"/>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Padding="3">
<TextBlock Text="{Binding StdWin}"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
