在xaml中,你通常必须在InteractionTriggers中有一个InteractionRequestTrigger,但我很好奇是否有办法在后面的代码中执行所有这些操作。我已经获得了一些代码并且正在运行,但我认为我的InteractionRequest中的Raised事件没有设置是错误的。
我相信很多人都想问你为什么要这样做?"但请暂时忽略它。
private void OnInteractionRequestEvent(InteractionRequestEventInfo info)
{
lock (_irLock)
{
var ir = new InteractionRequest<INotification>();
InteractionRequestTrigger irt = new InteractionRequestTrigger();
PopupNotificationAction pna = new PopupNotificationAction();
pna.ElementToParent = info.Parent;
pna.CenterOverAssociatedObject = true;
pna.IsModal = true;
pna.WindowContent = info.View;
irt.Actions.Add(pna);
irt.SourceObject = ir;
ir.Raise(info.Notification, info.Callback);
}
}
这是我到目前为止所做的 PopupNotificationAction是我们编写的,当以xaml的正常方式使用时。它来自PopupWindowAction
答案 0 :(得分:0)
所以,正式让我开始工作,我做了这些改变:
private void OnInteractionRequestEvent(InteractionRequestEventInfo info)
{
var ir = new InteractionRequest<INotification>();
InteractionRequestTrigger irt = new InteractionRequestTrigger();
PopupNotificationAction pna = new PopupNotificationAction();
pna.ElementToParent = info.Parent;
pna.CenterOverAssociatedObject = true;
pna.IsModal = true;
pna.WindowContent = info.View;
irt.Actions.Add(pna);
irt.Attach(parent); // added
irt.SourceObject = ir;
ir.Raise(info.Notification, () =>
{
try
{
info.Callback()
}
catch
{
// exception handling
}
finally
{
irt.Detach(); // added
}
);
}