I have a WPF that uses a TreeView and a HierarchiacalDataTemplate. When I set styling for the different levels, sometimes the foreground color for the text is White and sometimes its Black (depending on the background color). Here's my dilemma. When the user selects an item in the treeview, wpf applies a border (which is fine) and changes the foreground color of the text. For the items that already have a white foreground, its fine but for the items that have a black foreground the text virtual disappears. I can't really use property setters and triggers because the style doesn't apply universally to all nodes, just to certain ones. How can I disable WPF from changing the foreground color at all OnSelection? Below is my WPF code:
<TreeView Name="tvwConfig" VerticalAlignment="Stretch" DockPanel.Dock="Left" Width="300" Background="LightGray" ItemsSource="{Binding}" SelectedItemChanged="Treeview_SelectedItemChanged" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type cfg:AppConfig}" ItemsSource="{Binding Path=Services}">
<Border Width="200" BorderBrush="DarkBlue" Background="DarkBlue" BorderThickness="1" CornerRadius="2" Margin="2" Padding="2">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=ServerName}" FontWeight="Bold" Foreground="White" />
</StackPanel>
</Border>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type cfg:Service}" ItemsSource="{Binding Path=Queues}">
<Border Width="200" BorderBrush="RoyalBlue" Background="RoyalBlue" BorderThickness="1" CornerRadius="2" Margin="2" Padding="2">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="White" />
<TextBlock Text=" (" FontWeight="Bold" Foreground="White" />
<TextBlock Text="{Binding Path=Modality}" FontWeight="Bold" Foreground="White" />
<TextBlock Text=")" FontWeight="Bold" Foreground="White" />
</StackPanel>
</Border>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type cfg:Queue}" ItemsSource="{Binding Path=Statuses}">
<Border Width="200" BorderBrush="AliceBlue" Background="AliceBlue" BorderThickness="1" CornerRadius="2" Margin="2" Padding="2">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Path=Name}" FontWeight="SemiBold" />
</StackPanel>
</Border>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type cfg:Status}">
<Border Width="200" BorderBrush="White" Background="White" BorderThickness="1" CornerRadius="2" Margin="2" Padding="2">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text=" ("/>
<TextBlock Text="{Binding Path=Weight}" />
<TextBlock Text=")" />
</StackPanel>
</Border>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>