I am trying to close a usercontrol from a viewmodel that was opened as a window/dialog in a viewmodel button command.
Open a usercontrol as window/dialog: MainWindow >> Button >> Command via MainWindowViewModel >> Show usercontrol as window/dialog
Close the usercontrol that was opened in the above step: ????
Also I am wondering if I am violating the mvvm pattern, so if someone can please provide me with some proper examples as I am fairly new to the wpf MVVM pattern.
mainwindow button command in viewmodel:
private void ExecuteOtherMethod(object parameter)
{
registerWindow win = (registerWindow)Application.Current.MainWindow;
//win.pp.IsOpen = true;
win.bankRectangle.Visibility = Visibility.Visible;
Window window = new Window
{
WindowStyle = WindowStyle.None,
SizeToContent = SizeToContent.WidthAndHeight,
ResizeMode = ResizeMode.NoResize,
Content = new otherOptionsView()
};
window.Owner = win;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
}
usercontrol viewmodel to close the usercontrol:
private void ExecuteMethod(object parameter)
{
//otherOptionsView newview = new otherOptionsView();
//Window parentWindow = (Window)newview.Parent;
//parentWindow.Close();
var displayViews = App.Current.Windows.OfType<otherOptionsView>();
if (displayViews.Any())
displayViews.First().Close();
registerWindow win = (registerWindow)Application.Current.MainWindow;
win.bankRectangle.Visibility = Visibility.Collapsed;
}