PRISM: 区域未在RegionManager注册

4

我有一个自定义控件,它继承自用户控件。

public class CustomControl : ContentControl 
{
    public static readonly DependencyProperty VisualCompareControlProperty = DependencyProperty.Register("VisualCompareControl", typeof (FrameworkElement), typeof (CustomControl), new PropertyMetadata(default(FrameworkElement)));
    public FrameworkElement VisualCompareControl
    {
        get { return (FrameworkElement) GetValue(VisualCompareControlProperty); }
        set { SetValue(VisualCompareControlProperty, value); }
    }
}

这是我的“视图”:

<myNameSpace:CustomControl>
    <VisualCompareControl prism:RegionManager.RegionName="MyRegion" />
</myNameSpace:CustomControl>

在此区域导航和注入视图是标准的方法:
RegionManager.RequestNavigate("MyRegion", navigation, navigationParameter);

我在调试区域“MyRegion”时,发现它没有在RegionManager中注册。为什么?有什么想法吗?

1个回答

3

您必须通过声明一个区域适配器的控件来声明该区域。我假设您的类型为FrameworkElementVisualCompareControl控件没有这样的控件。

您可以创建自定义区域适配器,也可以使用三个带有Prism适配器的控件之一:ContentControlItemsControl或派生自Selector的控件。

由于CustomControl派生自ContentControl,因此您可以尝试:

<myNameSpace:CustomControl prism:RegionManager.RegionName="MyRegion" />

或者您可以直接使用ContentControl

<ContentControl prism:RegionManager.RegionName="MyRegion" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接