首页 > 解决方案 > MVVM 跨 WPF 区域实现

问题描述

我如何用 MVVM Cross 和 WPF 实现这个视图演示;菜单、标签和内容视图?我找不到任何实际示例如何做到这一点。这是一个过时的实现https://github.com/ThallisonRhanniel/MvvmCross-Samples/tree/master/XPlatformMenus但我想使用 MvvmCross(6.x) 和 MvvmCross.Platforms.Wpf(6.x)。

主窗口:

[MvxWindowPresentation(Identifier = nameof(MainWindow), Modal = false)]
public partial class MainWindow : MvxWindow<MainWindowViewModel>

菜单:

[MvxContentPresentation(WindowIdentifier = nameof(MainWindow), StackNavigation = true)]
[MvxRegion("MenuContent")]
[MvxViewFor(typeof(MenuViewModel))]
public partial class MenuView

标签栏:

[MvxContentPresentation(WindowIdentifier = nameof(MainWindow), StackNavigation = true)]
[MvxRegion("PageContent")]
[MvxViewFor(typeof(TabViewModel))]
public partial class TabView

使用区域属性;

public class MvxRegionPresentationAttribute : MvxBasePresentationAttribute
{
    public string RegionName { get; set; }
    public string WindowIdentifier { get; set; }
}

MainWindow.xaml 内部;

<Frame x:Name="MenuContent"
       Grid.Column="0"
       NavigationUIVisibility="Hidden"></Frame>

<Frame x:Name="PageContent"
       Grid.Column="1"
       NavigationUIVisibility="Hidden"></Frame>

如何在 MVVMCross 6.x 中实现区域?

标签: c#wpfmvvmviewmvvmcross

解决方案


在搜索了所有 mvvmcross wpf github 项目后,我发现了各种实现,但只有一个更新版本; https://github.com/eiadxp/MvvmCross.Platforms.Wpf.ItemsViewPresenter 它使用 MvvmCross(6.x) 和 MvvmCross.Platforms.Wpf(6.x)。


推荐阅读