簡體   English   中英

設置自定義樣式后,默認樣式丟失(例如顏色)

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

我使用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值可以顯示此顏色開關。

您需要繼承默認樣式:

<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}"確實告訴它繼承了當前的默認樣式,而只是“添加”您的設置器。

它應該是:

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

...如果您希望自定義樣式基於默認樣式。

我終於得到了答案。 我從另一個程序集改寫了我們的自定義樣式。 這在這里工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM