private void ShowFlyoutInternal(IDialogViewModel viewModel) { var view = (FrameworkElement)ViewLocator.GetViewForViewModel(viewModel); var flyout = view as Flyout ?? new Flyout { Content = view }; flyout.IsOpen = true; flyout.Position = Position.Right; flyout.IsModal = true; view.HorizontalAlignment = HorizontalAlignment.Left; flyout.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml") }); EventHandler closedHandler = null; closedHandler = (sender, args) => { viewModel.Closed -= closedHandler; flyout.IsOpen = false; }; viewModel.Closed += closedHandler; RoutedEventHandler closingFinishedHandler = null; closingFinishedHandler = (o, eventArgs) => { flyout.ClosingFinished -= closingFinishedHandler; Remove(flyout); }; flyout.ClosingFinished += closingFinishedHandler; Add(flyout); }
public Window ShowWindow(object viewModel, Window owningWindow = null) { var window = (Window)ViewLocator.GetViewForViewModel(viewModel); window.Owner = owningWindow; window.Show(); return(window); }
public Window ShowWindow <TViewModel>(Window owningWindow = null) { var window = (Window)ViewLocator.GetViewForViewModel <TViewModel>(); window.Owner = owningWindow; window.Show(); return(window); }
private static void OnViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(d)) { return; } var self = (ViewModelPresenter)d; self.Content = null; if (e.NewValue != null) { var view = ViewLocator.GetViewForViewModel(e.NewValue); self.Content = view; } }
public async Task ShowDialogAsync(DialogViewModel viewModel, MetroDialogSettings settings = null) { var view = ViewLocator.GetViewForViewModel(viewModel); var dialog = view as BaseMetroDialog; if (dialog == null) { throw new InvalidOperationException($"The view {view.GetType()} belonging to view model {viewModel.GetType()} does not inherit from {typeof(BaseMetroDialog)}"); } dialog.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml") }); var firstMetroWindow = Application.Current.Windows.OfType <MetroWindow>().First(); await firstMetroWindow.ShowMetroDialogAsync(dialog, settings); await viewModel.Task; await firstMetroWindow.HideMetroDialogAsync(dialog, settings); }