我使用 Prism Unity、WPF 和 Mvvm 在应用程序中创建了一个自定义确认窗口。我需要有关需要发送回视图模型的通知的帮助。我在详细记录视图中有这个,我们称之为 MyDetailView。
<!-- Custom Confirmation Window -->
<ie:Interaction.Triggers>
<interactionRequest:InteractionRequestTrigger
SourceObject="{Binding ConfirmationRequest, Mode=TwoWay}">
<mycontrols:PopupWindowAction1 IsModal="True"/>
</interactionRequest:InteractionRequestTrigger>
</ie:Interaction.Triggers>
如上图,我设置了交互Mode=TwoWay,这样确认弹窗就可以回传OK或Cancel按钮的点击结果。确认窗口按其应有的方式显示,但我不知道如何将按钮单击结果发送回我的视图模型,例如 MyDetailViewModel。这是主要问题。
编辑:这是引发 InteractionRequest 的 MyDetailViewMmodel 方法。
private void RaiseConfirmation()
{ConfirmationRequest
.Raise(new Confirmation()
{
Title = "Confirmation Popup",
Content = "Save Changes?"
}, c =>{if (c.Confirmed)
{ UoW.AdrTypeRos.Submit();}
这是 PopupWindow Action1 类。该问题的部分答案可能是如何实现“通知”和“完成交互”方法。
class PopupWindowAction1 : PopupWindowAction, IInteractionRequestAware
{
protected override Window GetWindow(INotification notification)
{ // custom metrowindow using mahapps
MetroWindow wrapperWindow = new ConfirmWindow1();
wrapperWindow.DataContext = notification;
wrapperWindow.Title = notification.Title;
this.PrepareContentForWindow(notification, wrapperWindow);
return wrapperWindow;
}
public INotification Notification
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public Action FinishInteraction
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
我需要在ConfirmWindow1中添加一些交互吗,比如这样?
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonUp">
<ei:CallMethodAction
TargetObject="{Binding RelativeSource={RelativeSource AncestorType=UserControl},
Path=DataContext}"
MethodName="DataContext.ValidateConfirm"/>
</i:EventTrigger>
</i:Interaction.Triggers>
我是否需要在按钮内进行这种类型的交互?如果是这样,我如何对其进行编码,以便它与调用交互的特定视图模型相对应。有什么建议么?谢谢。