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> |
Thank you.
Very nice!
Thanks a lot! Trying to find this for days!
Piece of cake... but this is what github is for. Glad to help...
BTW purist will say that you should move the template to a resource.
…On Wed, 4 Jan. 2023, 17:08 BaturalpDuran, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks a lot! Trying to find this for days!
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/c8cb125bc493c1ccac99b4098c7eeb60#gistcomment-4423469>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4PYWOSDNFTENFUGW2JDETWQUHV3BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA4DCOBZGA2TCNNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Ver helpful. Thank you.
Awesome!Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks