设置自定义样式后默认样式丢失(例如颜色)

问题描述:

我使用telerik的RadTreeView来显示带节点的树。要绑定IsExpanded物业我自己IsExpanded财产我用下面的代码片段:设置自定义样式后默认样式丢失(例如颜色)

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

这工作得很好,但迄今为止节点的高亮颜色从蓝色变成灰色。我如何保持原始风格并只添加setter属性?

编辑:

我使用Telerik的Windows8Theme和调整Windows8Palette。 在XAML中添加所提到的样式元素之前,所选元素的颜色是Windows8Palette的AccentColor(蓝色)。添加样式元素后,它似乎使用Windows8Palette的BasicColor(灰色)。我不知道究竟发生了什么,但比较RGB值显示了这个颜色开关。

+0

这听起来像'telerik'在某种程度上将'IsExpanded'属性连接到高亮颜色。你有没有尝试通过混合来调查风格? – XAMlMAX

我终于得到了答案。我从另一个程序集覆盖了我们的自定义样式。这里可以工作:

<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> 

你需要从默认继承的样式:

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

BasedOn="{x:Type telerik:RadTreeViewItem}"并告诉它继承当前默认的样式,只是“添加”您的二传手。

+0

谢谢你的快速回答。当我添加这个属性时,它说虽然:“指定的值不能分配。预期以下类型:”样式“”。 – telandor

+0

到目前为止,我已经发现它应该是:BasedOn = {StaticResource ResourceKey = {x:type telerik:RadTreeViewItem}} 这继承自telerik默认样式,但覆盖了自定义主题。 – telandor

它应该是:

<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> 

...如果你想立足于默认的自定义样式。

+0

非常感谢您的回复。这可以确保使用telerik默认样式。但我想使用添加Style元素之前使用的相同样式。这是一种自定义风格,而不是默认的telerik风格。 – telandor

+0

然后你应该基于这个自定义风格的风格:BasedOn =“{StaticResource TheXKeyOfTheCustomStyle}”> – mm8

+0

我想我没有一个StaticResource来根据我的风格。问题在于,当使用XAML样式元素时,我们使用的telerik Windows8Theme不再适用于树。出于某种原因,使用Windows8Palette的BasicColor,而不是在选择节点时使用AccentColor。在开头的问题中查看我的编辑。 – telandor