是否可以在没有 xaml 的情况下打开 WPF IneractionRequest (Prism)?
Is it possible to open a WPF IneractionRequest (Prism) without the xaml?
在 xaml 中,您通常必须在 InteractionTriggers 中有一个 InteractionRequestTrigger,但我很好奇是否有一种方法可以在代码隐藏中完成所有这些操作。我已经编写了一些代码 运行,但我认为问题在于我的 InteractionRequest 中的 Raised 事件没有设置。
我相信你们中的许多人都想问 "why are you doing this?" 但请暂时忽略它。
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
所以,为了正式让它工作,我做了这些更改:
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
}
);
}
在 xaml 中,您通常必须在 InteractionTriggers 中有一个 InteractionRequestTrigger,但我很好奇是否有一种方法可以在代码隐藏中完成所有这些操作。我已经编写了一些代码 运行,但我认为问题在于我的 InteractionRequest 中的 Raised 事件没有设置。
我相信你们中的许多人都想问 "why are you doing this?" 但请暂时忽略它。
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
所以,为了正式让它工作,我做了这些更改:
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
}
);
}