将值传递给 Child Window 表单 Parent 页面

Pass value to Child Window form Parent Page

我需要将值传递给 child Window.In child window 有两个文本 boxes.I 需要在 [=25= 中显示值] window 正在打开的文本框。

我试了下面的方法,我的Childwindowclass如下,

    public partial class ChildWindow:ChildWindow
    {
    public int abc {get;set;}
    public string value{get;set;}
    public ChildWindow()
    {
    InitializeComponent();          
    this.txtbox1.Text =  abc ; 
    this.txtbox2.Text =  value; 
    }

    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
    this.DialogResult = true;

    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
    this.DialogResult = false;
    }

    }

我的ParentWindow如下,

    private void EditButton_Click(System.Object sender, System.Windows.RoutedEventArgs e)
    {
    ChildWindow child= new ChildWindow();
    child.abc = 1;
    child.alue = "Hello"
    child.show();
    }

如何在 child window 控件打开时显示其值(来自 Parent)?

您可以创建 overloadconstructor

public ChildWindow(string abc,string value)
{
InitializeComponent();          
this.txtbox1.Text =  abc ; 
this.txtbox2.Text =  value; 
}

比这样创建 object 子窗口

ChildWindow child= new ChildWindow("abc","somevalue");

您可以更改以下内容:

public int abc {get;set;}
public string value{get;set;}

收件人:

public int abc
{
    get
    {
        int result = 0;
        int.TryParse(this.txtbox1.Text, out result);
        return result;
    }
    set
    {
        this.txtbox1.Text = value;
    }

}


public string value
{
    get
    {
        return this.txtbox2.Text;
    }
    set
    {
        this.txtbox2.Text = value;
    }

}

您的代码中的问题是,属性是在控件初始化期间分配的。不是在更改属性时。