WPF窗口返回值 [英] WPF Window Return Value

查看:174
本文介绍了WPF窗口返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,弹出窗口另一扇窗。我想第二个窗口,以便能够在按下一个按钮对象返回第一个窗口。我会怎么做呢?

I have a Window which pop-ups another Window. I want the second Window to be able to return an object to the first Window when a button is pressed. How would I do this?

推荐答案

您可以在第二个窗口上暴露的属性,从而使第一窗口可以找回。

You can expose a property on the second window, so that the first window can retrieve it.

public class Window1 : Window
{
    ...

    private void btnPromptFoo_Click(object sender, RoutedEventArgs e)
    {
        var w = new Window2();
        if (w.ShowDialog() == true)
        {
            string foo = w.Foo;
            ...
        }
    }
}

public class Window2 : Window
{
    ...

    public string Foo
    {
        get { return txtFoo.Text; }
    }

}

这篇关于WPF窗口返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆