如何在wpf中将值从一个窗口传递到另一个窗口 [英] how to pass a value from one window to another window in wpf

查看:411
本文介绍了如何在wpf中将值从一个窗口传递到另一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个窗口。

1. ListName

2.学生

我想将ListName中的值传递给学生

列表页面代码: -

i have two window.
1. ListName
2. Student
I wanna to pass value from ListName to Student
List page Code:-

string str = (dgRecord.Columns[0].GetCellContent(row) as TextBlock).Text;
            Student student = new Student();
            student.Tbox.Text = str;
            DialogResult = true;



和我的学生页面代码是: -

我声明Tbox像


and My student page code is:-
I declare Tbox like

public TextBox Tbox = new TextBox();



adn代码是: -


adn code is:-

ListName frm = new ListName();
           frm.ShowDialog();
           if (frm.DialogResult.HasValue && frm.DialogResult.Value)
           {
               txtID.Text = Tbox.Text;
               txtID.Focus();
           }



txtID.text为空为什么?

任何人都可以告诉我。


txtID.text is null why ??
anybody can me tell.

推荐答案

如果它们是单独的表单,那么你需要将它们视为单独的对象。



这些是基于WinForms的示例,但WPF系统是相同的:

传输信息两种形式之间,第1部分:父母对儿童 [ ^ ]

在两个表格之间传递信息,第2部分:儿童到父母 [ ^ ]

在两种形式之间传递信息,第3部分:儿童到儿童 [ ^ ]

所以技术是相同的,即使某些控件不同。
If they are separate forms, then you need to treat them as separate objects.

These are WinForms based examples, but the WPF system is the same:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
So the techniques are the same, even if some of the controls are different.


这篇关于如何在wpf中将值从一个窗口传递到另一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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