PRISM WPF 自定义交互请求 - 动态视图控件未正确显示
PRISM WPF Custom interaction request - dynamic view controls don't show correctly
我对 Prism/WPF 自定义交互请求弹出窗口有疑问。弹出窗口在第一次请求时正确呈现,但每个后续弹出窗口都重用相同的视图。这导致 TextBlock
控件连接文本、滚动条不可见、ItemsControl
项中的动态数据不可见、弹出窗口 window 大小错误等。是否可以强制创建每个新交互请求的新弹出窗口 window 或刷新弹出窗口中的所有控件?
为了显示弹出窗口,我使用了 PRISM 文档中的标准代码,例如弹出窗口实例化为:
PopUpViewModel displayData = reportCreator.GetReport();
this.CustomConfirmationRequest.Raise(displayData, res => {
if (res.Confirmed)
{ ... }
});
其中 PopUpViewModel
继承 Confirmation, IInteractionRequestAware
XAML 是:
<prism:InteractionRequestTrigger SourceObject="{Binding CustomConfirmationRequest, Mode=OneWay}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen" >
<prism:PopupWindowAction.WindowContent>
<popups:SoPopUp/>
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
你最好的办法是创建一个正确的视图模型来应对重复使用,例如 详细说明。
你 可以 尝试使用 RegionMemberLifetimeAttribute
,但我真的不希望它能帮到你,因为你没有进行导航...
而不是
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen">
<prism:PopupWindowAction.WindowContent>
<popups:SoPopUp/>
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
你可以使用
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen" WindowContentType = "{x:Type popups:SoPopUp}"/>
当您指定 WindowContent 时,加载此 xaml 时将创建一次 SoPopUp 实例。然后在每次触发 PopupWindowAction 时重复使用它。如果您指定 WindowContentType,则每次触发 PopupWindowAction 时都会重新创建一个 SoPopUp 实例。另请注意,DI 用于实例化 SoPopUp,以便 SoPopUp 构造函数可能具有要由 DI 解析的参数。
我对 Prism/WPF 自定义交互请求弹出窗口有疑问。弹出窗口在第一次请求时正确呈现,但每个后续弹出窗口都重用相同的视图。这导致 TextBlock
控件连接文本、滚动条不可见、ItemsControl
项中的动态数据不可见、弹出窗口 window 大小错误等。是否可以强制创建每个新交互请求的新弹出窗口 window 或刷新弹出窗口中的所有控件?
为了显示弹出窗口,我使用了 PRISM 文档中的标准代码,例如弹出窗口实例化为:
PopUpViewModel displayData = reportCreator.GetReport();
this.CustomConfirmationRequest.Raise(displayData, res => {
if (res.Confirmed)
{ ... }
});
其中 PopUpViewModel
继承 Confirmation, IInteractionRequestAware
XAML 是:
<prism:InteractionRequestTrigger SourceObject="{Binding CustomConfirmationRequest, Mode=OneWay}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen" >
<prism:PopupWindowAction.WindowContent>
<popups:SoPopUp/>
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
你最好的办法是创建一个正确的视图模型来应对重复使用,例如
你 可以 尝试使用 RegionMemberLifetimeAttribute
,但我真的不希望它能帮到你,因为你没有进行导航...
而不是
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen">
<prism:PopupWindowAction.WindowContent>
<popups:SoPopUp/>
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
你可以使用
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" WindowStartupLocation="CenterScreen" WindowContentType = "{x:Type popups:SoPopUp}"/>
当您指定 WindowContent 时,加载此 xaml 时将创建一次 SoPopUp 实例。然后在每次触发 PopupWindowAction 时重复使用它。如果您指定 WindowContentType,则每次触发 PopupWindowAction 时都会重新创建一个 SoPopUp 实例。另请注意,DI 用于实例化 SoPopUp,以便 SoPopUp 构造函数可能具有要由 DI 解析的参数。