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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18311260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:27:57  来源:igfitidea点击:

what is Behind Code for "{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"

wpfstylessettextstaticresource

提问by Kiran Ahir

This is my XAML Code

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

its similar behind c# code is

它的类似背后的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);

i do not know how can i replace

我不知道如何更换

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

with c# code. Grid is Devexpress's GridControl

用 C# 代码。Grid 是 Devexpress 的 GridControl

回答by Sheridan

The Styleclass has a constructor that accepts a Styleobject to base the new Styleon. You can also set the Style.BasedOnproperty as you have found.

Style类有一个接受一个构造函数Style对象以生成新Style的。您还可以设置Style.BasedOn您发现的属性。

You can access a default Styleset from your application Resourcessection using the following:

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

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

So please try the following:

因此,请尝试以下操作:

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