WPF MVVM 关闭当前窗体 打开新的窗体

原文:WPF MVVM 关闭当前窗体 打开新的窗体

登录成功窗体切换

1、xaml

点击事件将登录页面某个控件带回至ViewModel

<Button Content="登  录" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=pb_password}" Margin="30,10" Width="286" Height="40" Style="{StaticResource ButtonPrimary}"/>

2、viewmodel

  1. /// <summary>
  2. /// 登录事件
  3. /// </summary>
  4. public RelayCommand<System.Windows.Controls.PasswordBox> LoginCommand =>
  5. new Lazy<RelayCommand<System.Windows.Controls.PasswordBox>>(() =>
  6. new RelayCommand<System.Windows.Controls.PasswordBox>(Login)).Value;
  1. private void Login(System.Windows.Controls.PasswordBox password)
  2. {
  3. WIndex window = new WIndex();
  4. window.Show();
  5. Window.GetWindow(password).Close();
  6. }

 

WPF MVVM 关闭当前窗体 打开新的窗体

上一篇:数据倾斜通用处理方式


下一篇:kafka简介