window1的代码,这个类创建window2并创建我想发送到windows2的事件
public partial class Window1 : Window
{ //my event
public class modificoHojaEventArgs : EventArgs
{
public ClaseHoja miHoja;
}
public delegate void modificoHojaEventHandler(object sender,
modificoHojaEventArgs e);
public event modificoHojaEventHandler ModificoHojaHandler;
protected virtual void OnAceptoHoja(modificoHojaEventArgs e)
{
if (this.ModificoHojaHandler != null)
this.ModificoHojaHandler(this, e);
}
//constructor
public Window1()
{
InitializeComponent();
}
//create window2 w2 and send argumentos to w2
private void BotonModificar_Click(object sender, RoutedEventArgs e)
{
window2 w2 = new window2();
w2.Owner = this;
w2.ShowDialog();
modificoHojaEventArgs argumentos = new modificoHojaEventArgs();
argumentos.miHoja = data;
OnAceptoHoja(argumentos);
}
我希望接收参数的window2代码
public partial class DatosDeLaHoja : Window
{
public DatosDeLaHoja( )
{
Window1 winn = new Window1();
这是我的问题,我无法从此窗口2获取window1
winn=(Window1)PresentationSource.FromVisual(this).RootVisual
winn.ModificoHojaHandler += winn_modifico;
InitializeComponent();
}
//receive argumentos using e variable
void winn_modifico(object sender, Window1.modificoHojaEventArgs e)
{
cHoja = e.miHoja;
}
答案 0 :(得分:0)
创建此
public Window window1 {get; set; }
然后在窗口1
private void BotonModificar_Click(object sender, RoutedEventArgs e)
{
window2 w2 = new window2();
w2.window1 = this;
w2.Owner = this;
w2.ShowDialog();
modificoHojaEventArgs argumentos = new modificoHojaEventArgs();
argumentos.miHoja = data;
OnAceptoHoja(argumentos);
}
答案 1 :(得分:0)
我不确定你打算通过这样做实现什么,但是你只需要将参数传递给 DatosDeLaHoja()该参数显然应该是 window1 对象