0

私のプロジェクトでは、login.xaml という名前のログイン ページがあり、MVVM アプローチを使用するための loginViewModel.cs がありました。 childwindow を閉じることを意味します。ここでは、viewmodel(loginviewmodel) から childwindow(login.xaml) を閉じる必要があります。

ログイン.xaml:

private void btnLogin_Click(object sender, RoutedEventArgs e)
        {

            if (txtuser.Text.Trim() != "" && txtpass.Password != "")
            {
                (DataContext as LoginViewModel).UserValidation(txtuser.Text.Trim(),txtpass.Password.Trim());
            }
        }

loginviewmodel.cs:

public void UserValidation(string name, string pass)
        {
            IsBusy =true;
            uname=name;
            pword=pass;
            // ----* (Follow * for the continuation )

        }

*-->ここで、子ウィンドウを閉じる必要があります..閉じる方法..

4

1 に答える 1

3

同じ問題が発生して解決しました...だから、子ウィンドウとキャンセルボタンがあります:

<Button x:Name="CancelButton" Content="Cancel" Command="{Binding CancelCommand}" CommandParameter="{Binding ElementName=SignUpPopup}" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1"/>

そして、私がすることは、ExecuteCancelCommand パラメーター、param を介して Name="SignUpPopup" を持つオブジェクト Child Window を渡すことです。ビューモデルには次のものがあります。

public void ExecuteCancelCommand(object param)
        {
            (param as Signup).Close();
           // MessageBox.Show("Window should close now");
        }

Signup は子ウィンドウのタイプです。お役に立てれば、

ヴラド

于 2013-03-08T12:23:10.037 に答える