2016-08-14 75 views
2

How do i achive this?如何讓MahApps CleanWindow工作?

我想有CleanWindow的標題,我在WPF新的,所以我對這個真的

奮鬥下面是MainWindow.xaml代碼:

<Controls:MetroWindow x:Class="Twitch_Notifier.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:Twitch_Notifier" 
    mc:Ignorable="d" 
    TitleCaps="False" 
    ShowTitleBar="True" 
    ShowIconOnTitleBar="False" 
    ResizeMode="CanMinimize" 
    Title="Twitch Notifier" Height="350" Width="525" WindowStartupLocation="CenterScreen" 
    GlowBrush="{DynamicResource AccentColorBrush}" 
    Style="{DynamicResource CleanWindowStyleKey}"> 

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/Resources/Icons.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 

<Controls:MetroWindow.RightWindowCommands> 
    <Controls:WindowCommands> 
     <Button Content="settings" /> 
    </Controls:WindowCommands> 
</Controls:MetroWindow.RightWindowCommands> 

<Grid> 

</Grid> 

But i get this error

適用於App.xaml的代碼:

<Application x:Class="Twitch_Notifier.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:Twitch_Notifier" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <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/BaseDark.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Clean/Clean.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

我怎樣才能解決這個問題?感謝您的幫助

回答

1

這是a limitation of the designer但解決方法很簡單:

1)鑄造的窗口式的MetroWindow式的資源(MyCleanWindowStyle)

2)應用MetroWindow樣式,而不是

<Controls:MetroWindow 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:Views;assembly=gasby.Wpf" 
     xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
     ShowTitleBar="True" ShowIconOnTitleBar="False" ResizeMode="CanMinimize" 
     Title="CleanWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen" 
     GlowBrush="{DynamicResource AccentColorBrush}" 
     Style="{DynamicResource MyCleanWindowStyle}"> 
    <Controls:MetroWindow.Resources> 
     <ResourceDictionary> 
      <Style x:Key="MyCleanWindowStyle" 
        TargetType="{x:Type Controls:MetroWindow}" 
        BasedOn="{StaticResource CleanWindowStyleKey}"/> 

      ... 

     </ResourceDictionary> 
    </Controls:MetroWindow.Resources> 

    ... 

    <Grid> 
    </Grid> 
</Controls:MetroWindow> 

你提到想要設置標題,這是由代碼Title="CleanWindow"完成。 TitleCaps確定 標題是否顯示在全部大寫(CAPITAL字母)中。默認值是TitleCaps="True"