Application.Resources中的多个条目

时间:2015-01-10 20:04:25

标签: c# wpf

<Application x:Class="Myprogram.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:Myprogram.ViewModels"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:helper="clr-namespace:Myprogram.Helper"
             StartupUri="Views\LoginView.xaml"
             mc:Ignorable="d">        
    <Application.Resources>
        <helper:MathConverter x:Key="MathConverter"/>
        <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
                    Source="Themes/ExpressionLight.xaml">    
        </ResourceDictionary>
    </Application.Resources>        
</Application>

我的<Application.Resources>元素中有2个条目。该文件可以正常使用其中一个,但两者都不起作用。我收到了错误

  

x:需要关键属性

如何添加两者?

1 个答案:

答案 0 :(得分:4)

您需要创建一个合并资源字典

<Application.Resources>
   <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="Themes/ExpressionLight.xaml"/>    
      </ResourceDictionary.MergedDictionaries>
      <helper:MathConverter x:Key="MathConverter"/>
   </ResourceDictionary>
</Application.Resources> 
相关问题