1

我有一个 ResourceDictionary CustomStyles.xaml,我已经在两个视图中实现了它。在第一个视图中,所有模板和样式都可以正常工作。虽然在第二个视图中我的模板没有应用到我的DataGrid,当我进入视图时,会显示以下输出。仍然在我的 VS2012 DesignerHeaderTemplates中显示正确。

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>

最后是我的数据模板:

<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>

我的设计师截图 在此处输入图像描述

以及它如何看待应用程序: 在此处输入图像描述

请帮忙!!!并询问您是否需要更多信息!

4

1 回答 1

2

ResourceDictionary我的 .xml 文件中没有我的 xaml App.xaml。我不知道为什么......虽然如果我把它放在那里一切正常。

于 2013-02-27T22:31:48.820 回答