This is a migrated thread and some comments may be shown as answers.

Reset colors after setting style

10 Answers 353 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rico
Top achievements
Rank 1
rico asked on 10 Aug 2017, 01:49 PM

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

Sort by
0
Sia
Telerik team
answered on 15 Aug 2017, 08:40 AM
Hello,

I will need some details about your implementation:
  1. Which is the theme that you use in your application?
  2. 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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rico
Top achievements
Rank 1
answered on 16 Aug 2017, 09:32 AM
Thank your for your answer.
 
Where do I find the information about which theme and theming mechanism we use? I would say it is all default.

Your solution doesn't work for me because RadTreeViewItemStyle is not in the StaticResources.

0
Sia
Telerik team
answered on 17 Aug 2017, 09:23 AM
Hello,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rico
Top achievements
Rank 1
answered on 17 Aug 2017, 09:48 AM

Indeed we do: We use the Windows8Theme and adjust further settings such as its palette.

0
rico
Top achievements
Rank 1
answered on 18 Aug 2017, 02:42 PM
Before adding the style element the color of a selected element was the AccentColor (blue) of the Windows8Palette. After adding the style element it seems to use the BasicColor (gray) of the Windows8Palette. I don't know what exactly is going on but comparing the RGB values shows this color switch.
0
Sia
Telerik team
answered on 22 Aug 2017, 07:42 AM
Hello,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rico
Top achievements
Rank 1
answered on 25 Aug 2017, 07:05 AM

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>

0
rico
Top achievements
Rank 1
answered on 25 Aug 2017, 07:32 AM
Sorry, false alarm. Doesn't work.
0
Sia
Telerik team
answered on 28 Aug 2017, 09:09 AM
Hello,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rico
Top achievements
Rank 1
answered on 13 Sep 2017, 12:38 PM

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>
Tags
TreeView
Asked by
rico
Top achievements
Rank 1
Answers by
Sia
Telerik team
rico
Top achievements
Rank 1
Share this question
or