2017-04-23 191 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> 
所有資源