且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

棱镜/MEF:如何在不对区域名称进行硬编码的情况下注册ViewWithRegion

更新时间:2022-06-24 22:35:33

正如Meleak在其评论中已经提到的:使用静态类

As Meleak already mentioned in his comment: Use a static class

namespace Infrastructure
{
    public static class RegionNames
    {
        public const string MainRegion = "MainRegion";
    }
}

在您的xaml代码中,您可以按以下方式使用区域名称:

In your xaml code you can use the region name as follows:

<UserControl 
    xmlns:Inf="clr-namespace:Infrastructure;assembly=Infrastructure"
    xmlns:Regions="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism">
    <ContentControl Regions:RegionManager.RegionName="{x:Static Inf:RegionNames.MainRegion}"/>
</UserControl>