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

/// <summary>
        /// 登錄事件
        /// </summary>
        public RelayCommand<System.Windows.Controls.PasswordBox> LoginCommand =>
            new Lazy<RelayCommand<System.Windows.Controls.PasswordBox>>(() =>
                new RelayCommand<System.Windows.Controls.PasswordBox>(Login)).Value;
private void Login(System.Windows.Controls.PasswordBox password)
{
    WIndex window = new WIndex();
                        window.Show();

                        Window.GetWindow(password).Close();
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章