【发布时间】:2017-03-26 22:06:10
【问题描述】:
我想在我的应用程序中使用 mahapps.metro 的对话框。我的窗口是普通的window。
public partial class MainWindow : Window
不是
MetroWindow
在我的按钮方法中我写了这个:
var metroWindow = (Application.Current.MainWindow as MetroWindow);
await metroWindow.ShowMessageAsync("Foo", "Bar");
我在App.xaml.cs 中添加了一个ThemeManager
protected override void OnStartup(StartupEventArgs e)
{
Tuple<AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Application.Current);
ThemeManager.ChangeAppStyle(Application.Current,
ThemeManager.GetAccent("Green"),
ThemeManager.GetAppTheme("BaseDark")); // or appStyle.Item1
base.OnStartup(e);
}
在App.xaml里面我加了
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cobalt.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
当我执行我的程序时,我得到一个
NullReferenceException
因为metroWindow == null
我该如何解决这个问题?
【问题讨论】:
-
你需要找到父母
MetroWindow无论如何,所以不清楚为什么不MainWindow? -
MahApps 对话框不能在没有 MetroWindow 的情况下使用,因为窗口样式中有一些东西可以与 Dialogs 一起使用。
-
@punker76 感谢您的评论!
标签: c# wpf xaml mahapps.metro