码迷,mamicode.com
首页 > 移动开发 > 详细

MahApps.Metro怎么调用消息窗口

时间:2015-05-26 20:33:14      阅读:1130      评论:0      收藏:0      [点我收藏+]

标签:

网上查看了好多资料,没有找到很清楚明了的结果,经过了多天的研究,无意发现了这个方法来进行全局调用

效果展示:

技术分享

1.主窗口代码

  public partial class MainWindow : MetroWindow
    {
        public MainWindow()
        {
            InitializeComponent();
 
            MessageExt.Instance.ShowDialog = ShowDialog;
        }
        public async void ShowDialog(string message, string title = "提示")
        {
            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "关闭",
                ColorScheme = MetroDialogColorScheme.Theme
            };
            MessageDialogResult result = await this.ShowMessageAsync(title, message, MessageDialogStyle.Affirmative, mySettings);
        }

 }

2.单例类代码

public sealed class MessageExt
    {
        private static readonly MessageExt instance = new MessageExt();
        private MessageExt()
        {
        }

        public static MessageExt Instance
        {
            get
            {
                return instance;
            }
        }

        public Action<string, string> ShowDialog { get; set; }
    }

3.调用方法:

MessageExt.Instance.ShowDialog("查询", "提示");

其他请自行实现。

 

官方调用消息窗口的demo代码

 private async void ShowMessageDialog(object sender, RoutedEventArgs e)
        {
            // This demo runs on .Net 4.0, but we‘re using the Microsoft.Bcl.Async package so we have async/await support
            // The package is only used by the demo and not a dependency of the library!
            MetroDialogOptions.ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme;

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Hi",  //确定
                NegativeButtonText = "Go away!", //否
                FirstAuxiliaryButtonText = "Cancel",
//第一个自定义按钮, SecondAuxiliaryButtonText为第二个自定义按钮 ColorScheme
= UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme }; MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro!", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings); if (result != MessageDialogResult.FirstAuxiliary) //这里编写点击后的代码 await this.ShowMessageAsync("Result", "You said: " + (result == MessageDialogResult.Affirmative ? mySettings.AffirmativeButtonText : mySettings.NegativeButtonText + Environment.NewLine + Environment.NewLine + "This dialog will follow the Use Accent setting.")); } private async void ShowLimitedMessageDialog(object sender, RoutedEventArgs e) { var mySettings = new MetroDialogSettings() { AffirmativeButtonText = "Hi", NegativeButtonText = "Go away!", FirstAuxiliaryButtonText = "Cancel", MaximumBodyHeight = 100, ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme }; MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro!" + string.Join(Environment.NewLine, "abc","def","ghi", "jkl","mno","pqr","stu","vwx","yz"), MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings); if (result != MessageDialogResult.FirstAuxiliary) await this.ShowMessageAsync("Result", "You said: " + (result == MessageDialogResult.Affirmative ? mySettings.AffirmativeButtonText : mySettings.NegativeButtonText + Environment.NewLine + Environment.NewLine + "This dialog will follow the Use Accent setting.")); }

 

MahApps.Metro怎么调用消息窗口

标签:

原文地址:http://www.cnblogs.com/xcsn/p/4531365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!