1
我得到了一個ResourceDictionary CustomStyles.xaml
,我在兩個視圖中實現了它。 在第一個視圖中,所有模板和樣式都可以正常工作。雖然在第二個視圖中我的模板不適用於我的DataGrid
,並且當我進入視圖時顯示以下輸出。仍然在我的VS2012 Designer中,HeaderTemplates
顯示正確。wpf資源模板不適用
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TransparentWhiteBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TransparentWhiteBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='GrayBrush7'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='Gray3'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='Gray3'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ControlBackgroundBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TextBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='GrayBrush7'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TextBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TransparentWhiteBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='TransparentWhiteBrush'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='GrayBrush7'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='Gray3'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='Gray3'
這些資源不是我的,我沒有在我看來應用它們。 我實現資源:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
<ResourceDictionary Source="/Fluent;Component/Themes/Metro/White.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="/PQS;component/Resources/CustomStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
,最後我的DataTemplate:
<DataGrid ItemsSource="{Binding Items.View}" Style="{DynamicResource InputDataGridStyle}" Grid.Row="1" Name="InputGrid" Loaded="InputGrid_Loaded" KeyUp="InputGrid_OnKeyUp">
<DataGrid.Columns>
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridIndexHeaderTempalte}" CellTemplate="{DynamicResource InputGridIndexCellTempalte}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridTimeStampHeaderTemplate}" CellTemplate="{DynamicResource InputGridTimeStampCellTemplate}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridUserHeaderTemplate}" CellTemplate="{DynamicResource InputGridUserCellTemplate}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridValueHeaderTemplate}" CellTemplate="{DynamicResource InputGridValueCellTempalte}" Visibility="{Binding ElementName=InputGrid, Path=DataContext.CharacteristicMeasure.Characteristic.CharacteristicType.IsBool,Converter={StaticResource boolToInv}, ConverterParameter=true}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridValueHeaderTemplate}" CellTemplate="{DynamicResource InputGridBoolValueCellTempalte}" Visibility="{Binding ElementName=InputGrid, Path=DataContext.CharacteristicMeasure.Characteristic.CharacteristicType.IsBool,Converter={StaticResource boolToInv}}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridValidHeaderTemplate}" CellTemplate="{DynamicResource InputGridValidCellTemplate}" />
<DataGridTemplateColumn HeaderTemplate="{DynamicResource InputGridTextHeaderTemplate}" CellTemplate="{DynamicResource InputGridTextCellTemplate}" />
</DataGrid.Columns>
</DataGrid>
例如一個報頭 - 和細胞模板
<DataTemplate x:Key="InputGridIndexHeaderTempalte">
<TextBlock Text="#" />
</DataTemplate>
<DataTemplate x:Key="InputGridIndexCellTempalte">
<TextBlock Text="{Binding Index}" />
</DataTemplate>
我的設計師
的屏幕截圖,在這裏它的外觀在應用:
請幫助!並詢問您是否需要更多信息!
在第一個datagridTemplateColumn中拼錯了數據模板的名稱。你在哪裏定義App.xaml中的資源字典?你的CustomStyles.xaml是什麼樣的? – jfin3204 2013-02-25 19:23:09
這裏是我的CustomStyles.xaml:http://pastebin.com/U54KmFi3;和我的觀點:http://pastebin.com/CjVUs5at;我沒有將資源應用到我的App.xaml。我已將它應用於我的觀點。 – JuHwon 2013-02-26 08:59:49
謝謝你的提示!我將它添加到我的App.xaml - 知道它的工作..是一種絕望 – JuHwon 2013-02-26 11:17:53