写委托方法的问题
我在向 EventHandler 添加参数时遇到问题。 当用户选择消息并选择他想要发送给谁时,我有一个控件。
我需要处理程序 OnConfirmForwarClosed 以某种方式添加变量项。
我该怎么做呢?
private void inboxContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
var item = (RadMenuItem)e.Source;
RadWindow.Confirm("Do you want forward this message to item.DataContext.HandlerName ?", OnConfirmForwarClosed);
}
private void OnConfirmForwarClosed(object sender, WindowClosedEventArgs e)
{
if (e.DialogResult == true)
{
//here I need item from caller
}
}
编辑 我需要一个可以通过此解决方案获得的结果:
RadWindow.Confirm("Do you want forward this message to item.DataContext.HandlerName ?",(s,ea)=>
{
if(ea.DialogResult==true)
{
MessageBox.Show((item.DataContext as Handler).HandlerId.ToString());
}
});
I have a problem with adding parameters to EventHandler.
I have a control when user select message and choose to who he want to send it.
I need to handler OnConfirmForwarClosed add in some way variable item.
How can I do it?
private void inboxContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
var item = (RadMenuItem)e.Source;
RadWindow.Confirm("Do you want forward this message to item.DataContext.HandlerName ?", OnConfirmForwarClosed);
}
private void OnConfirmForwarClosed(object sender, WindowClosedEventArgs e)
{
if (e.DialogResult == true)
{
//here I need item from caller
}
}
EDIT
I need a result which I can get by this solution:
RadWindow.Confirm("Do you want forward this message to item.DataContext.HandlerName ?",(s,ea)=>
{
if(ea.DialogResult==true)
{
MessageBox.Show((item.DataContext as Handler).HandlerId.ToString());
}
});
如果我正确理解你的问题,你不想将局部变量“提升”到 lambda 中,例如...
...而是你想保留
OnConfirmForwarClosed
(大概是订阅此处未显示的事件)。如果这是正确的,那么您有几个选择:1.
您可以以不同的方式安排您的方法:
2.
设置对象字段:
3.
增选现有
OnConfirmForwarClosed
参数之一:等等...
If i understand your question correctly, you don't want to "lift" the local variable into lambda, such as...
...and instead you want to keep the
OnConfirmForwarClosed
(presumably to subscribe to events not shown here). If that's correct, then you have couple of options:1.
You could just arrange your methods differently:
2.
Set the object field:
3.
Co-opt one of the existing
OnConfirmForwarClosed
parameters:Etc, etc...