【问题标题】:wpf Resource template not appliedwpf 资源模板未应用
【发布时间】:2013-02-25 14:40:45
【问题描述】:

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

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>

我的设计师的截图

以及它如何看待应用程序:

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

【问题讨论】:

  • 在第一个 datagridTemplateColumn 中,您拼错了数据模板的名称。您在哪里定义 App.xaml 中的资源字典?您的 CustomStyles.xaml 是什么样的?
  • 这是我的 CustomStyles.xaml :pastebin.com/U54KmFi3 ;我的看法:pastebin.com/CjVUs5at;我没有将资源应用到我的 App.xaml。我已将它应用到我的视图中。
  • 谢谢你的提示!!!!我将它添加到我的 App.xaml - 知道它有效.. 有点绝望

标签: wpf xaml templates resources mvvm-light


【解决方案1】:

我的 App.xaml 中没有我的 xaml ResourceDictionary。我不知道为什么......虽然如果我把它放在那里一切都很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 2014-01-16
    • 2011-07-12
    • 2013-04-03
    • 2013-02-02
    • 2017-12-03
    • 1970-01-01
    相关资源
    最近更新 更多