0
我已經創建了與已經用於其內部運作定義的資源一個DataGrid一個用戶控件:現在如何在已有資源的WPF組件上設置XAML中的資源?
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="23" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="ExcelFilterButton"
Grid.Column="0"
Margin="0,0,0,0"
BorderThickness="0"
Click="ExcelFilterButton_Click"
Focusable="False"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
Tag="{Binding}">
<Image Width="19"
Height="19"
Source="Resources\NoSortNoFilter.png"
Tag="{Binding}" />
</Button>
<TextBlock Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding}" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
,而試圖在應用程序中使用的組件,並與下面的XAML
<adg:AdvancedSortFilterDataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}" />
</adg:AdvancedSortFilterDataGrid.Resources>
設置一些顏色
獲取我下面的運行時錯誤:
'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.' Line number '200' and line position '34'.
我試圖用資源屬性的組件,只需添加資源到現有資源,但獲得相同的錯誤。這裏的屬性:
Public Shadows Property Resources As ResourceDictionary
Get
Return dataGrid.Resources
End Get
Set(value As ResourceDictionary)
For Each Key As Object In value.Keys
dataGrid.Resources.Add(Key, value(Key))
Next
End Set
End Property
希望有人能讓我直接。
編輯:的InnerException:
Cannot re-initialize ResourceDictionary instance.