telandor
telandor

Reputation: 869

Default style lost (e.g. colors) after setting custom style

I use the RadTreeView from telerik to show a tree with nodes. 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?

EDIT:

I use the telerik Windows8Theme and adjust the Windows8Palette. Before adding the mentioned style element in XAML the color of a selected element was the AccentColor (blue) of the Windows8Palette. After adding the style element it seems to use the BasicColor (grey) of the Windows8Palette. I don't know what exactly is going on but comparing the RGB values shows this color switch.

Upvotes: 0

Views: 172

Answers (3)

telandor
telandor

Reputation: 869

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>

Upvotes: 0

mm8
mm8

Reputation: 169150

It should be:

<Style x:Key="ItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}" BasedOn="{StaticResource {x:Type telerik:RadTreeViewItem}}">
    <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
</Style>

...if you want to base your custom style on the default one.

Upvotes: 0

Christoph Fink
Christoph Fink

Reputation: 23093

You need to inherit the style from the default:

<Style x:Key="ItemContainerStyle"
       TargetType="{x:Type telerik:RadTreeViewItem}"
       BasedOn="{x:Type telerik:RadTreeViewItem}">
    <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
</Style>

The BasedOn="{x:Type telerik:RadTreeViewItem}" does tell it to inherit the current default style and just "add" your setter.

Upvotes: 0

Related Questions