Application.Resources 中的多个条目
Multiple entries in Application.Resources
<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:key attribute required
如何同时添加?
您需要创建一个合并资源字典
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/ExpressionLight.xaml"/>
</ResourceDictionary.MergedDictionaries>
<helper:MathConverter x:Key="MathConverter"/>
</ResourceDictionary>
</Application.Resources>
<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:key attribute required
如何同时添加?
您需要创建一个合并资源字典
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/ExpressionLight.xaml"/>
</ResourceDictionary.MergedDictionaries>
<helper:MathConverter x:Key="MathConverter"/>
</ResourceDictionary>
</Application.Resources>