Created
October 11, 2017 23:56
-
-
Save LGM-AdrianHum/c8cb125bc493c1ccac99b4098c7eeb60 to your computer and use it in GitHub Desktop.
Changing WPF Listbox SelectedItem text color and highlight/background Color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="ListBoxStyle.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:src="clr-namespace:ListBoxStyle" | |
Title="MainWindow" Height="350" Width="525"> | |
<Window.Resources> | |
<Style x:Key="_ListBoxItemStyle" TargetType="ListBoxItem"> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="ListBoxItem"> | |
<Border Name="_Border" | |
Padding="2" | |
SnapsToDevicePixels="true"> | |
<ContentPresenter /> | |
</Border> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsSelected" Value="true"> | |
<Setter TargetName="_Border" Property="Background" Value="Yellow"/> | |
<Setter Property="Foreground" Value="Red"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</Window.Resources> | |
<Grid> | |
<ListBox ItemContainerStyle="{DynamicResource _ListBoxItemStyle}" | |
Width="200" Height="250" | |
ScrollViewer.VerticalScrollBarVisibility="Auto" | |
ScrollViewer.HorizontalScrollBarVisibility="Auto"> | |
<ListBoxItem>Hello</ListBoxItem> | |
<ListBoxItem>Hi</ListBoxItem> | |
</ListBox> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ver helpful. Thank you.