MahApps 资源字典错误

MahApps Resource Dictionary error

所以,今天我在我的 WPF 项目中安装了 MahApps。一切顺利,直到我想使用内置样式。

这是我的 App.xaml:

<Application x:Class="WpfApplication1.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:WpfApplication1"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <BitmapImage x:Key="logoImage" UriSource="Images/Logo.png" />
    <BitmapImage x:Key="profileButtonImage" UriSource="Images/ProfileButton.png" />
    <BitmapImage x:Key="settingsButtonImage" UriSource="Images/SettingsButton.png" />
    <BitmapImage x:Key="profileIconImage" UriSource="Images/profileIcon.png" />
    <BitmapImage x:Key="listenIconImage" UriSource="Images/listenIcon.png" />
    <BitmapImage x:Key="statsIconImage" UriSource="Images/statsIcon.png" />
    <BitmapImage x:Key="accountButtonImage" UriSource="Images/accountButton.png" />
    <BitmapImage x:Key="pauseButtomImage" UriSource="Images/pause-button.png" />
    <BitmapImage x:Key="playButtomImage" UriSource="Images/play-button.png" />
    <BitmapImage x:Key="stopButtomImage" UriSource="Images/stop-button.png" />
    <BitmapImage x:Key="doneButtonImage" UriSource="Images/doneButton.png" />
    <BitmapImage x:Key="arrowButtonImage" UriSource="Images/arrow.png" />
    <BitmapImage x:Key="doneButtonHoverImage" UriSource="Images/doneButtonHover.png" />
    <FontFamily x:Key="Novo">/Fonts/#Novecentosanswide-Medium</FontFamily>

    <Style x:Key="ButtonStyle">
        <Setter Property="Border.Background" Value="#262a33" />
        <Style.Triggers>
            <Trigger  Property="Border.IsMouseOver" Value="True">
                <Setter Property="Border.Background" Value="#1d2027" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

BitmapImages 用于我的一些按钮。我的问题是,当我尝试编译时出现以下错误:

All objects added to an IDictionary must have a Key attribute or some other type of key associated with them.
Each dictionary entry must have an associated key.

我安装了所有 3 个 MahApps NuGet,您知道为什么会出现这些错误吗?

将所有资源包装在另一个 ResourceDictionary 中,并在其中添加 MahApp 资源作为 MergedDictionaries

谢谢 Ruben,为我工作只将所有资源包装在 ResourceDictionary

 <Application.Resources>

    <ResourceDictionary>
        <!--Estilo Validação-->
    <Style TargetType="TextBox">
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <StackPanel>
                        <AdornedElementPlaceholder x:Name="placeholder"/>
                        <TextBlock FontSize="12" Foreground="Red"  
                                   Text="{Binding ElementName=placeholder,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="True">
                <Setter Property="Background" Value="Red"/>
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, 
                  Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!--FIM Estilo Validação-->

        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>