Hi
I'm currently testing the UI for WPF and there's one problem I can't seem to solve. I wrote a small APF application using the Windows8-Theme. I change some Fonts, Font sizes and Colors of the palette and apply it as my application theme in the Code Behind.
Now I've got a TreeView where I'm dynamically adding children. This works as intended so far, but when an item in the TreeView is selected, the background color of the Selection-Border is blue (which is fine) but the font color is still black, which makes the name of the selected item hard to read.
So I tried to change the Foreground-Property of the currently selected item. There are two ways I tried out yet. First, I tried to change the style via XML by binding a style with a trigger to the ItemContainerStyle property of the TreeView, like this:
And this is the Resource for the style:
It kind of does the job but only kind of, because it also changes the Foreground color of all child elements of the selected item. I don't know if I did anything wrong there or if forgot something (I'm still fairly new to WPF) but this is not the behavior I expected.
I tried another approach: good old event driven Code Behind. Just change the Foreground color of the sender when the PreviewSelected event fired:
But same problem here: the Font color of the selected item changes, but so does the font color of all child items. I first thought this had something to do with event routing but that seems not to be the case. Since I'm adding children dynamically with Code Behind, I tried changing the Foreground color first and then added the child nodes but with the same result. They somehow seem to inherit the Foreground color of the parent.
Now I know that since I'm using the Windows8 Theme that I could make a local copy of the Theme-XAML, reference this one instead of the standard ones in the GAC from Telerik and change the color directly there. But I'm still curious as to why the control is behaving in they way I'm experiencing it in this case.
Any suggestions?
Regards,
Steve.
I'm currently testing the UI for WPF and there's one problem I can't seem to solve. I wrote a small APF application using the Windows8-Theme. I change some Fonts, Font sizes and Colors of the palette and apply it as my application theme in the Code Behind.
Now I've got a TreeView where I'm dynamically adding children. This works as intended so far, but when an item in the TreeView is selected, the background color of the Selection-Border is blue (which is fine) but the font color is still black, which makes the name of the selected item hard to read.
So I tried to change the Foreground-Property of the currently selected item. There are two ways I tried out yet. First, I tried to change the style via XML by binding a style with a trigger to the ItemContainerStyle property of the TreeView, like this:
<
telerik:RadTreeView
ItemContainerStyle
=
"{StaticResource SelectedTreeViewItem}"
x:Name
=
"TreeViewDomain"
>
And this is the Resource for the style:
<
Style
x:Key
=
"SelectedTreeViewItem"
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
>
<
Style.Triggers
>
<
Trigger
Property
=
"IsSelected"
Value
=
"true"
>
<
Setter
Property
=
"Foreground"
Value
=
"White"
/>
</
Trigger
>
</
Style.Triggers
>
</
Style
>
It kind of does the job but only kind of, because it also changes the Foreground color of all child elements of the selected item. I don't know if I did anything wrong there or if forgot something (I'm still fairly new to WPF) but this is not the behavior I expected.
I tried another approach: good old event driven Code Behind. Just change the Foreground color of the sender when the PreviewSelected event fired:
void
__childItem_PreviewSelected(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
var __currentNode = (RadTreeViewItem) sender;
__currentNode.Foreground = Brushes.White;
}
But same problem here: the Font color of the selected item changes, but so does the font color of all child items. I first thought this had something to do with event routing but that seems not to be the case. Since I'm adding children dynamically with Code Behind, I tried changing the Foreground color first and then added the child nodes but with the same result. They somehow seem to inherit the Foreground color of the parent.
Now I know that since I'm using the Windows8 Theme that I could make a local copy of the Theme-XAML, reference this one instead of the standard ones in the GAC from Telerik and change the color directly there. But I'm still curious as to why the control is behaving in they way I'm experiencing it in this case.
Any suggestions?
Regards,
Steve.