c# - Mahapp ShowMessageAsync MvvM

标签 c# wpf mvvm mahapps.metro

我使用 MVVM 模式创建了最简单的 WPF 项目。如何从我的 viewModel 调用 ShowMessageAsync

 if (DisciplineText!="")
 {
     Disciplines.Add(new Discipline(){ChairID = SelectedChair.ChairID,SemesterID = SelectedSemester.SemesterID,Discipline1 = DisciplineText});
     Context.SaveChanges();
 }
 else
 {
     //  ShowMessageAsync????????
 }

最佳答案

MetroWindow metroWindow = Application.Current.MainWindow as MetroWindow;
metroWindow.MetroDialogOptions.ColorScheme = MetroDialogColorScheme.Accented; // set the theme
await MetroWindow.ShowMessageAsync("Title", "Message");

你需要使用:

using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

希望对你有所帮助:)

关于c# - Mahapp ShowMessageAsync MvvM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26825250/

相关文章:

c# - GroupBy LINQ 中的两个属性之一

c# - 在 Angular ASP.NET Core 2.0 应用程序中使用 LinkedIn api 和 Oauth 2.0 进行身份验证

wpf - 使用 MVVM 在另一个控件中执行方法

WPF/MVVM - ItemsControl 中的 WrapPanel,添加子项上的动画

c# - 为什么我的 Silverlight XAML 绑定(bind)单元测试失败?

c# - 我们可以锁定目录吗?

c# - AvalonEdit (C#) XSHD 文件中的自定义属性

C#:在搜索/计算期间禁用按钮

c# - 如何检查我是否正在删除(退格键、删除或 'Cut' )RichTextBox 中的 UIElement?

wpf - 检测我的页面是否需要保存的最佳方法是什么 - 使用 WPF MVVM