【问题标题】:what is Behind Code for "{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"“{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}”的代码背后是什么
【发布时间】:2013-08-21 02:23:54
【问题描述】:

这是我的 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

【问题讨论】:

    标签: wpf styles settext staticresource


    【解决方案1】:

    Style 类有一个构造函数,该构造函数接受一个 Style 对象以作为新 Style 的基础。你也可以按照你找到的设置Style.BasedOn属性。

    您可以使用以下命令从您的应用程序Resources 部分访问默认的Style 集:

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

    所以请尝试以下方法:

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

    【讨论】:

    • 它抛出错误 {"'GridRowContent' TargetType 与元素'TableView'的类型不匹配。"}.
    猜你喜欢
    • 2011-02-06
    • 2014-10-17
    • 2010-12-17
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    相关资源
    最近更新 更多