2013-08-19 27 views
4

這是我的XAML代碼是什麼代碼背後的 「{StaticResource的{dxgt:GridRowThemeKey獲取ResourceKey = RowStyle}}」

<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

Style類有一個構造函數,它接受一個Style對象以將新的Style作爲基礎。您也可以將Style.BasedOn屬性設置爲您找到的屬性。

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

所以,請嘗試以下方法:

您可以從您的應用程序Resources部分使用下面的訪問默認Style

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

它拋出錯誤{「 'GridRowContent' TargetType的不不匹配元素'TableView'的類型。「}。 –

相關問題