2017-04-23 190 views
0

所以,今天我在我的WPF项目中安装了MahApps。一切顺利,直到我想使用内置样式。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. 

我安装了MahApps NuGets的所有3,你有什么想法,为什么这些错误出现在哪里?

回答

0

包裹里面所有的另一个ResourceDictionary并且在一个资源添加MahApp资源MergedDictionaries

0

感谢的鲁本,对我的工作只包内的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> 
所有资源