InteractionRequest<INotification>
Prism通过InteractionRequest 来实现弹窗交互,它是一个泛型接口,不同的类型对应不同类型的弹窗方式。
Notification
在使用InteractionRequest
的时候需要在,xaml中需要注册一个Trigger:
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" />
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
那么i
是什么呢?interactivity
这个是微软内置的类库,他提供了一组用户交互的类,比如我们这里用到的EventTrigger
可以用来执行事件触发的操作。
在使用的时候,先引入xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
或者xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
,然后在xaml中使用他:
<i:Interaction.Triggers>
<i:EventTrigger>
</i:EventTrigger>
</i:Interaction.Triggers>
而 prism:PopupWindowAction 的 IsModal=True意味着弹框不被关闭的时候,父窗体无法使用。我刚搜索了一下,这个词的翻译竟然“模态”。
在code-behind中声明,使用INotification
类型:
public InteractionRequest<INotification> NotificationRequest { get; set; }
在command的回调函数中就可以使用NotificationRequest:
NotificationRequest.Raise(new Notification { Content = "Notification Message", Title = "Notification" }, r => Title = "Notified");
最后通过ConfirmationRequest.Raise()
方法来实现调用弹窗,这里将Title
修改为“Notified”。
Confirmation
<prism:InteractionRequestTrigger SourceObject="{Binding ConfirmationRequest}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" />
</prism:InteractionRequestTrigger>
public InteractionRequest<IConfirmation> ConfirmationRequest { get; set; }
ConfirmationRequest.Raise(new Confirmation {Title = "Confirmation",Content = "Confirmation Message" },r => Title = r.Confirmed ? "Confirmed" : "Not Confirmed");
https://www.bbsmax.com/A/A2dmReOBze/