In my program I have a TreeView in which the user will select different items from. There are a few items in my TreeView that are customized upon creation in my c# code-behind.
Like so:
public static TreeViewItem newItem = new TreeViewItem() //Child Node { Header = new StackPanel //ICON { Orientation = Orientation.Horizontal, Children = { new Border { Width = 12, Height = 14, Background = Brushes.Blue, BorderThickness = new Thickness(1.0), BorderBrush = Brushes.Black }, new Label { Content = "Node1" } } } }; I would like these items to display WHITE foregrounds when they are selected (just like the default node behavior).
This is what I have tried so far in XAML. It is a style template that I have set for TreeViewItems. I receive no compiler errors, but for some reason when I run the program my TreeView is not visible.
<Style TargetType="{x:Type TreeViewItem}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TreeViewItem}"> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True" > <Setter Property="Foreground" Value="White" /> </Trigger> <Trigger Property="IsSelected" Value="False" > <Setter Property="Foreground" Value="Black" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> How can I fix this so that all of my TreeView nodes display white foregrounds when selected?
TextBlockwould it allow theForegroundchange?