无法使用 Name/Key NavigationPaneButton 找到资源
Cannot find a Resource with the Name/Key NavigationPaneButton
我正在尝试引用 styles.xaml 中的 NavigationPaneButton 资源。我已经在不同的资源文件中定义了它们,并以正确的顺序在 app.xaml 中正确地链接了它们。但我仍然得到异常
"Cannot find a Resource with the Name/Key NavigationPaneButton"
有什么我遗漏的吗?
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style TargetType="Button" x:Key="WasHamburguerButton">
<Setter Property="Background" Value="{ThemeResource NavigationPaneButton}" />
<Setter Property="Foreground" Value="{ThemeResource NavigationPaneText}"/>
</Style>
</ResourceDictionary>
我已经在 AppTheme.xaml
中定义了资源
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<SolidColorBrush x:Key="NavigationPaneText" Color="{ThemeResource NavigationPaneTextColor}"/>
<SolidColorBrush x:Key="NavigationPaneButton" Color="{ThemeResource NavigationPaneButtonColor}"/>
</ResourceDictionary>
以及 AppColor.xaml
中的颜色
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Color x:Key="NavigationPaneTextColor">#ffffff</Color>
<Color x:Key="NavigationPaneButtonColor">#D13438</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
这是我的app.xaml
<Application
x:Class="WindowsUniversalApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WindowsUniversalApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/AppColors.xaml"/>
<ResourceDictionary Source="Resources/AppTheme.xaml"/>
<ResourceDictionary Source="Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
如果你 link 他们像这样,它将起作用:
样式 -> AppTheme -> AppColors
所以,AppTheme 知道 AppColors:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestImage.Resources">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Resources/AppColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="NavigationPaneText" Color="{ThemeResource NavigationPaneTextColor}"/>
<SolidColorBrush x:Key="NavigationPaneButton" Color="{ThemeResource NavigationPaneButtonColor}"/>
</ResourceDictionary>
Styles 知道 AppTheme:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestImage.Resources">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Resources/AppTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Button" x:Key="WasHamburguerButton">
<Setter Property="Background" Value="{ThemeResource NavigationPaneButton}" />
<Setter Property="Foreground" Value="{ThemeResource NavigationPaneText}"/>
</Style>
</ResourceDictionary>
我正在尝试引用 styles.xaml 中的 NavigationPaneButton 资源。我已经在不同的资源文件中定义了它们,并以正确的顺序在 app.xaml 中正确地链接了它们。但我仍然得到异常
"Cannot find a Resource with the Name/Key NavigationPaneButton"
有什么我遗漏的吗?
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style TargetType="Button" x:Key="WasHamburguerButton">
<Setter Property="Background" Value="{ThemeResource NavigationPaneButton}" />
<Setter Property="Foreground" Value="{ThemeResource NavigationPaneText}"/>
</Style>
</ResourceDictionary>
我已经在 AppTheme.xaml
中定义了资源<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<SolidColorBrush x:Key="NavigationPaneText" Color="{ThemeResource NavigationPaneTextColor}"/>
<SolidColorBrush x:Key="NavigationPaneButton" Color="{ThemeResource NavigationPaneButtonColor}"/>
</ResourceDictionary>
以及 AppColor.xaml
中的颜色<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Color x:Key="NavigationPaneTextColor">#ffffff</Color>
<Color x:Key="NavigationPaneButtonColor">#D13438</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
这是我的app.xaml
<Application
x:Class="WindowsUniversalApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WindowsUniversalApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/AppColors.xaml"/>
<ResourceDictionary Source="Resources/AppTheme.xaml"/>
<ResourceDictionary Source="Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
如果你 link 他们像这样,它将起作用:
样式 -> AppTheme -> AppColors
所以,AppTheme 知道 AppColors:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestImage.Resources">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Resources/AppColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="NavigationPaneText" Color="{ThemeResource NavigationPaneTextColor}"/>
<SolidColorBrush x:Key="NavigationPaneButton" Color="{ThemeResource NavigationPaneButtonColor}"/>
</ResourceDictionary>
Styles 知道 AppTheme:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestImage.Resources">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Resources/AppTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Button" x:Key="WasHamburguerButton">
<Setter Property="Background" Value="{ThemeResource NavigationPaneButton}" />
<Setter Property="Foreground" Value="{ThemeResource NavigationPaneText}"/>
</Style>
</ResourceDictionary>