I want to use the dialog's of mahapps.metro in my application. My window is a normal window
.
public partial class MainWindow : Window
not a
MetroWindow
Inside my button method I wrote this:
var metroWindow = (Application.Current.MainWindow as MetroWindow);
await metroWindow.ShowMessageAsync("Foo", "Bar");
I've added an ThemeManager
inside App.xaml.cs
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);
}
And inside App.xaml
I added
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cobalt.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
When I execute my programm, I get an
NullReferenceException
because metroWindow
== null
How can I solve this problem?