我试图从在视图模型按钮命令中作为窗口/对话框打开的视图模型关闭用户控件。
打开一个用户控件作为窗口/对话框: MainWindow >> Button >> Command via MainWindowViewModel >> Show usercontrol as window/dialog
关闭上一步打开的用户控件:????
另外我想知道我是否违反了 mvvm 模式,所以如果有人可以为我提供一些适当的例子,因为我对 wpf MVVM 模式相当陌生。
视图模型中的主窗口按钮命令:
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();
}
关闭用户控件的用户控件视图模型:
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;
}
30秒到达战场
潇潇雨雨
相关分类