What is behind the code for "{StaticResource {dxgt: GridRowThemeKey ResourceKey = RowStyle}}"

This is my XAML code

<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 c # code

 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 I can replace

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

with c # code. The grid is a Devexpress GridControl

+4
source share
1 answer

The Style class has a constructor that accepts a Style object to set a new Style . You can also set the Style.BasedOn property, as you already found.

You can access the default Style setting from your Resources application using the following:

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

So try the following:

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

Source: https://habr.com/ru/post/1497768/


All Articles