如何使MahApps CleanWindow工作?

时间:2016-08-14 00:33:35

标签: c# wpf xaml mahapps.metro

How do i achive this?

我想在标题上使用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 个答案:

答案 0 :(得分:1)

它是a limitation of the designer,但解决方法很简单:

1)在Window(MyCleanWindowStyle)中将Window风格转换为MetroWindow风格

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"

相关问题