To bind the IsExpanded Property to my own IsExpanded property I use the following snippet:
<Style TargetType="{x:Type telerik:RadTreeViewItem}" x:Key="ItemContainerStyle" >
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
</Style>
This works fine so far but the highlight color of the nodes turned from blue into grey. How can I keep the original style and only add the setter property?
10 Answers, 1 is accepted
I will need some details about your implementation:
- Which is the theme that you use in your application?
- Which is the theming mechanism that you use - StyleManager or implicit themes?
Generally we recommend using implicit style that targets RadTreeViewItem instead of using the ItemContainerStyle property. You need to base it on our style by setting BasedOn as follows:
<
Style
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
BasedOn
=
"{StaticResource RadTreeViewItemStyle}"
>
<
Setter
Property
=
"IsExpanded"
Value
=
"{Binding Path=IsExpanded,Mode=TwoWay}"
/>
</
Style
>
Regards, Sia
Progress Telerik
Your solution doesn't work for me because RadTreeViewItemStyle is not in the StaticResources.
It seems that you use our OfficeBlack theme with XAML binaries (or said another way - StyleManager). More information about styling Telerik UI for WPF controls can be found in our documentation.
Still I am not sure which is the blue color that is missing since in our Office Black theme there is only gray and orange highlights as seen from the attached screenshot.
Do you set ApplicationTheme somewhere in your application? ]
StyleManager.ApplicationTheme =
new
Office_BlackTheme();
Regards,
Sia
Progress Telerik
Indeed we do: We use the Windows8Theme and adjust further settings such as its palette.
Still I am not sure what causes the described issue. Please find attached a simple project with a TreeView where a custom ItemContainerStyle is set. By default the TreeView has gray background for MouseOver and Selected states of its items as seen from the attached screenshot. You said that there was an accent color before setting the style which disappeared which means that you have customized some of the palette colors as you said before. Can you modify the project with all palette settings so I can check what could be wrong with it?
Again if you use NoXAML binaries and merge the needed theme resources, such custom styles as the ItemContainerStyle one need to be based on ours. But if your case is setting a theme by StyleManager, then everything should work as expected.
Regards,
Sia
Progress Telerik
I've figured out the answer. I didn't put the style element into a merged dictionary.
This here works:
<telerik:radGridView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<Style TargetType="{x:Type telerik:RadTreeViewItem}" x:Key="ItemContainerStyle" >
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
< /Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</telerik:radGridView.Resources>
Could you please modify the previously attached project, so I can observe the exact setup of the resources in your application? Also the theming mechanism is important - do you use StyleManager or implicit styles? Otherwise it is difficult to understand what causes the unwanted behavior.
Regards,
Sia
Progress Telerik
I finally got the answer. I overwrote our custom style from another assembly. This here works:
<
telerik:radGridView.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source="pack://application:,,,/OtherAssembly,component/existingStyles.xaml />
</
ResourceDictionary.MergedDictionaries
>
<
Style
BasedOn
=
"{StaticResource xKeyOfStyleToExtendFromExistingStyles}"
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
>
<
Setter
Property
=
"IsExpanded"
Value
=
"{Binding Path=IsExpanded, Mode=TwoWay}"
/>
</
Style
>
</
ResourceDictionary
>
</
telerik:radGridView.Resources
>