单击按钮时,将数据从子窗口移动到主窗口 [英] Moving Data From Child Window To Main window When Button Clicked

查看:85
本文介绍了单击按钮时,将数据从子窗口移动到主窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Wpf应用程序,当我单击按钮时,从主窗口显示了一个新的子窗口,该子窗口中发生了一些动作,然后我想当单击子窗口中的按钮时,将数据表移至主窗口中的任何人都可以帮助我做到这一点..?
==============
我的问题是单击按钮时如何将数据从子窗口传递到主窗口
感谢

I have Wpf Application , from the Main Window when i clicked button a new child window is shown , some actions happens in this child window ,then i want when a button in child window is clicked , a data table is moved to the Main Window any one can help me in doing that,..?
===============
my question about how can i pass the data from the child window to the main window when button clicked
thanks

推荐答案



您可以使用事件方法将值从子级"传递给父级".

假设我们有两个类,分别是Parent和Child.然后在Child类中创建一个事件,例如

Hi,

you can use event method to pass values from Child to Parent.

Suppose We have two classes names Parent and Child. Then create an event in Child class like

public delegate ValueChangedHandler(DataTable DT);
public event ValueChangedHandler ValueChanged;



现在从Button事件点击中引发该事件



Now raise this event from Button event click

if(ValueChanged!=null)
{
   //DT: Suppose it is the desired object to return
   ValueChanged(DT);
}



现在进入Parent类,在这里您必须处理此事件,例如



Now come to Parent class, here you have to handle this event like

Child objChild=new Child();
objChild.ValueChanged += new ValueChangedHandler(objChild_ValueChanged);
objChild.Show();



新方法将使用名称"objChild_ValueChanged"创建,例如



New method will create with the name "objChild_ValueChanged" like

void objChild_ValueChanged(DataTable DT)
{
  //TODO: Now you can use this value which in coming from Child class.
}



问候
Ankit



regards
Ankit


在子窗口中创建公共属性/成员.假设MyDataTable是子窗口中的公共属性.

您必须使用以下(类似)代码打开子窗口.

Create public property/member in the child window. Say, MyDataTable is a public property in the Child Window.

You must have used the following (similar) code to open the Child Window.

MyChildWindow child = new MyChildWindow();
child.Show();



现在,将数据表值从ChildWindow分配给MyDataTable属性.您可以从父窗口访问它,如



Now assign the data table value to MyDataTable property from the ChildWindow. You can access it from the Parent Window like,

DataTable table = child.MyDataTable;


您需要在新窗口上创建一个表(从子窗口传递数据)-隐藏一个在子窗口上.
You need to create a table on the new window (pass data from child window) - hide the one on the child window.


这篇关于单击按钮时,将数据从子窗口移动到主窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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