WPF Prism w/Unity:在登录前折叠或隐藏 shell 中的导航菜单 [英] WPF Prism w/ Unity: collapse or hide nav menu from shell before login

查看:103
本文介绍了WPF Prism w/Unity:在登录前折叠或隐藏 shell 中的导航菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 C# .NET 4、Prism 和 Unity 设置了一个完整的应用程序,它在 MVVM 模式的 ViewModel 上实现了 INavigationAware 接口.我的窗口(Shell.xaml)目前非常简单(RegionName 的静态字符串以避免魔术字符串):

I have set up a complete application using C# .NET 4, Prism and Unity that implements the INavigationAware interface on the ViewModel of an MVVM pattern. My window (Shell.xaml) is very simple at the moment (static string for RegionName to avoid magic strings):

<Grid>
  <ContentControl prism:RegionManager.RegionName="{x:Static Infrastructure:RegionNames.ContentRegion}" />
</Grid>

我的每个视图都包含允许用户使用集中式 CompositeCommand 打开另一个视图的按钮,我在 Shell 中将一个 DelegateCommand 附加到该视图,如下所示:

Each of my views contains buttons that allow the user to open another view using a centralized CompositeCommand to which I attach a DelegateCommand in the Shell like so:

<Button Name="AcceptButton" Content="Accept"
            Command="{x:Static Infrastructure:ApplicationCommands.NavigateCommand}"
            CommandParameter="{x:Type Concrete:ViewB}"

ApplicationCommands.cs

public static class ApplicationCommands {
    public static CompositeCommand NavigateCommand = new CompositeCommand();
}

ShellViewModel.cs

public ShellViewModel(IRegionManager regionManager) {
        _regionManager = regionManager;
        NavigateCommand = new DelegateCommand<object>(Navigate, CanNavigate);
        ApplicationCommands.NavigateCommand.RegisterCommand(NavigateCommand);
    }

private void Navigate(object navigatePath) {
        if (navigatePath != null) {
            _regionManager.RequestNavigate(RegionNames.ContentRegion, navigatePath.ToString(), NavigationCallback);
        }                  
    }

我还绑定了几个视图,导航运行良好.现在是失败的变化.在每个屏幕上设置随机按钮确实是无效的,并且与良好的设计背道而驰,因此我试图将按钮拉出集中工具栏.我已将 ViewA.xaml 按钮代码从 ViewA.xaml 文件(其中包含更多内容,但由于矫枉过正的原因未显示)中提取出来,并将其放入 ViewAButonn.xaml 文件中.然后我修改了 Shell.xaml 并添加了第二个区域:

I have several more views tied in and the navigation is working great. Now comes the changes that are failing. Having random buttons on each screen is really ineffective and contrary to good design so I am trying to pull the buttons out for a centralized toolbar. I have pulled the ViewA.xaml button code out of the ViewA.xaml file ( which contains much more content but not shown for overkill reasons ) and put it into a ViewAButonn.xaml file. I then modified the Shell.xaml and add a second region:

<Grid>
  <ContentControl prism:RegionManager.RegionName="{x:Static Infrastructure:RegionNames.ContentRegion}" />
  <ContentControl prism:RegionManager.RegionName="{x:Static Infrastructure:RegionNames.NavRegion}" />
</Grid>

我可以毫无问题地将我的新 ViewAButton.xaml 添加到该区域,当我单击它时,View 内容会被正确放置到 ContentRegion 中.

I can add my new ViewAButton.xaml to the region without any issue and when I click it the View contents are then placed properly into the ContentRegion.

我的问题出现在这里.我的第一个屏幕是 TOS 协议屏幕,在单击接受"按钮之前无法显示工具栏.我很害怕在 ViewModel 中处理这个问题,因为我现在已经正确解耦了.我是否修改视图以包含可以在导航期间读取以隐藏区域的属性?如果是这样,我可以在导航过程中的哪个位置访问由 Unity 激活的视图?我的所有视图都实现了一个 IView 接口,该接口只根据 MSDN 上关于设置适当棱镜 MVVM 的说明公开了一个 IVewModel.如何在 TOS 接受屏幕上隐藏这个新工具栏?

My issue arises here though. My first screen is a TOS agreement screen that cannot display the toolbar until "Accept" button is clicked. I am terrified at the thought of handling this in the ViewModel as I have it properly decoupled right now. Do I modify the View to contain a property that can be read during navigation to hide the region? If so where in the navigation process can I get access to the View that is activated by Unity? All of my views implement an IView interface that just exposes an IVewModel as per the MSDN instruction on setting up a proper prism MVVM. How can I hide this new toolbar on the TOS acceptance screen?

推荐答案

根据我的理解,不可能折叠 Region.视图将被隐藏,但 区域 所在的空间将保持空白.

Based on my understanding it would not be possible to collapse a Region. The View would get Hidden but the space where the Region is located would remain empty.

如果您希望 TOS 屏幕填满整个窗口,您可以创建两个级别的区域:

例如,您可以在 Shell 视图 中声明一个WindowRegion"区域,该区域填充完整的窗口 以及 TOS 屏幕 和定义的CustomRegionsView"将在哪里注册.

For example, you could declare a "WindowRegion" Region in the Shell View which fills the complete Window and where the TOS screen and a defined "CustomRegionsView" would get registered.

然后,CustomRegionsView 将定义您上面提到的两个 Regions,以便应用可以在 TOS 屏幕之间导航 以及您描述的两个区域的任何视图.

Then, the CustomRegionsView would define both Regions you mentioned above so the App can navigate between the TOS screen and any View with the two regions you described.

因此,当从 TOS 屏幕点击接受"按钮时,导航导航>CustomRegionsView 也应针对在 ContentRegionNavRegion 上注册的特定视图 执行.

Therefore, when "Accept" button is clicked from the TOS screen, Navigation to the CustomRegionsView should be performed as also to the particular Views which are registered on the ContentRegion and NavRegion.

希望这对您有帮助.

这篇关于WPF Prism w/Unity:在登录前折叠或隐藏 shell 中的导航菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆