什么是代码“{StaticResource {dxgt:GridRowThemeKey ResourceKey = RowStyle}}”

时间:2013-08-19 10:12:26

标签: wpf styles settext staticresource

这是我的XAML代码

<Window x:Class="Q316995.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
        xmlns:local="clr-namespace:Q316995"
        Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <ResourceDictionary>
        <Style x:Key="LastRowHighlighted"
                BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"
                TargetType="{x:Type dxg:GridRowContent}">
        </Style>
    </ResourceDictionary>
</Window.Resources>
</Window>

与c#代码相似的是

Binding _Binding = new Binding();
_Binding.Converter = new LastRowHighlighter();

Setter _Setter = new Setter();
_Setter.Property = GridRowContent.FontWeightProperty;
_Setter.Value = _Binding;

Style _Style = new System.Windows.Style();
//_Style.BasedOn = new Style(typeof(GridRowContent));
_Style.TargetType = typeof(GridRowContent);
_Style.Setters.Add(_Setter);

grid.Resources.Add("LastRowHighlighted", _Style);

我不知道如何更换

BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"

使用c#代码。 Grid是Devexpress的GridControl

1 个答案:

答案 0 :(得分:1)

Style类有一个构造函数,它接受Style对象作为新Style的基础。您也可以设置Style.BasedOn属性。

您可以使用以下内容从应用Style部分访问默认Resources集:

Application.Current.TryFindResource(typeof(GridRowContent));

请尝试以下方法:

Style style = new Style(typeof(GridRowContent), Application.Current.TryFindResource(
typeof(GridRowContent)));