WPF引用MahApps.Metro

MahApps.Metro是一款win10扁平化风格的开源控件库。

  • 安装MahApps.Metro

    项目右键,管理NuGet程序包,浏览,搜索MahApps.Metro,安装;

  • 应用

    App.xaml内容如下,Steel.xaml为默认主题颜色,可修改。

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

    MainWindow.xaml中MainWindow改为Controls:MetroWindow;

    添加引用

xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"

    后台文件修改为 public partial class MainWindow;

  • 修改主题
Accent newAccent = ThemeManager.GetAccent("Red");
AppTheme newTheme = ThemeManager.GetAppTheme("BaseDark"); 
ThemeManager.ChangeAppStyle(Application.Current, newAccent, newTheme);

 

  • 对话框
private async void MainWindwo_Closing(object sender, CancelEventArgs e)
{
    e.Cancel = true;
    var mySettings = new MetroDialogSettings()
    {
        AffirmativeButtonText = "确定",    // Confirm
        NegativeButtonText = "关闭",       // Close
        AnimateShow = true,
        AnimateHide = false
    };
    // Confirm to close; Sure to close ?
    var result = await this.ShowMessageAsync("关闭确认", "确定关闭窗口吗?", MessageDialogStyle.AffirmativeAndNegative, mySettings);
    if (result == MessageDialogResult.Affirmative)
    {
        System.Windows.Application.Current.Shutdown();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值