Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

wpf listbox binding change style of selected item

<Window.Resources>

<DataTemplate x:Key="ItemTemplate">
    <TextBlock Text="{Binding}" Foreground="Red" />
</DataTemplate>

<DataTemplate x:Key="SelectedTemplate">
    <TextBlock Text="{Binding}" Foreground="White" />
</DataTemplate>

<Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
    <Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}" />
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}" />
        </Trigger>
    </Style.Triggers>
</Style>

</Window.Resources>
<ListBox x:Name="lstItems" ItemContainerStyle="{StaticResource ContainerStyle}" />
Comment

PREVIOUS NEXT
Code Example
Csharp :: asp.net listbox disable selection 
Csharp :: generate a dropdown list from array data using razor .net mvc 
Csharp :: c# get out of for loop 
Csharp :: asp.net call controller from another controller 
Csharp :: linq contains 
Csharp :: c# check if string contains character multiple times 
Csharp :: c# 10 null checl 
Csharp :: .net core get runtime version 
Csharp :: list with search bar uwp c# 
Csharp :: unity GUI TextField enter 
Csharp :: color rgb to float c# 
Csharp :: c# sbyte 
Csharp :: unity save scene at runtime 
Csharp :: strinng.indexOf c# 
Csharp :: hashtable in c# 
Csharp :: c# yield return ienumerable 
Csharp :: how to stop a coroutine unity c# 
Csharp :: Transpose Matrix C Sharp 
Csharp :: How can I get my stripe customer ID? 
Csharp :: what dotnet command does 
Csharp :: pork hub 
Csharp :: c# how to refresh input field 
Csharp :: mock async method c# reutrnd 
Csharp :: discord bot c# how to refresh message 
Csharp :: c++ printwindow chrome 
Csharp :: clear highlight winforms treeview 
Csharp :: c# enum key value 
Csharp :: unity time.fixeddeltatime 
Csharp :: C# milisecond to h m s 
Csharp :: unity update not called 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =