2014-01-29 459 views
0

我想绑定CornerRadius值。将CornerRadius绑定到相关属性

CornerRadius="{Binding CornerRadiusInfoBtn}" 

这是TitleBar中的代码。

这是我的财产。

 public CornerRadius CornerRadiusInfoBtn 
    { 
     get { return (CornerRadius)GetValue(CornerRadiusInfoBtnProperty); } 
     set { SetValue(CornerRadiusInfoBtnProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for CornerRadiusInfoBtn. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty CornerRadiusInfoBtnProperty = 
     DependencyProperty.Register("CornerRadiusInfoBtn", typeof(CornerRadius), typeof(TitleBar), new PropertyMetadata(new CornerRadius(0.0,0.0,2.0,2.0))); 

但是那里没有圆角。怎么了?

+0

圆角在哪里?它是否在CornerRadius类中? –

+0

您是否将数据上下文设置为“TitleBar”的实例? – PoweredByOrange

+0

当我设置一个大于0的值时,角落被舍入。 – user3197157

回答

0

如果你宣布你的DependencyPropertyTitleBar.xaml.cs文件,那么你的TitleBar.xaml文件应包含声明这样一个Border

<Border CornerRadius="{Binding CornerRadiusInfoBtn, RelativeSource={RelativeSource 
    AncestorType={x:Type YourXmlNamespacePrefix:TitleBar}}, Mode=OneWay}}" ... /> 

你要么需要设置DataContext属性本身(不建议除快速演示),或者使用上述的RelativeSource Binding来查找该属性。