【问题标题】:WPF Prism, Set several dependency properties of a View (UserControl) from inside ShellWPF Prism,从外壳内部设置视图(用户控件)的几个依赖属性
【发布时间】:2015-08-13 01:05:16
【问题描述】:

Prism中,每个View 都是UserControl,我有一个View 包括一个dependency property,就像这样(在MyView.xaml.cs 内):

public int WidgetCornerRadius
{
    get { return (int)GetValue(WidgetCornerRadiusProperty); }
    set { SetValue(WidgetCornerRadiusProperty, value); }
}
public static readonly DependencyProperty CornerRadiusProperty =
    DependencyProperty.Register(
        "CornerRadius",
        typeof(int),
        typeof(MyView),
        new UIPropertyMetadata(7));

我在下面的RegionShell.xaml)中显示了MyView.xaml

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

现在我的问题是如何从Shell 内部填充视图的CornerRadius dependency property?我需要注册一个新的RegionAdapter 吗?你能告诉我怎么做吗?

我想要这样的东西:

<ContentControl prism:RegionManager.RegionName="TargetRegion"
                CornerRadius="3" />

【问题讨论】:

    标签: wpf xaml user-controls prism


    【解决方案1】:

    除了将此 CornerRadius 传递给您的视图之外,您是否可以不只是从视图中查找相对源以找到该属性?这样应该会容易得多。假设您有一个依赖于它的边框,您所要做的就是这样

     <Border CornerRadius="{Binding RelativeSource={RelativeSource AncestorType={x:Type HereComesyourType}}, Path=CornerRadius}"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多