[英]Binding CornerRadius to Dependency Property
我想绑定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)));
但是没有圆角。 怎么了?
如果在TitleBar.xaml.cs
文件中声明了DependencyProperty
,则TitleBar.xaml
文件应包含这样声明的Border
:
<Border CornerRadius="{Binding CornerRadiusInfoBtn, RelativeSource={RelativeSource
AncestorType={x:Type YourXmlNamespacePrefix:TitleBar}}, Mode=OneWay}}" ... />
您要么需要将DataContext
属性设置为其自身(除非进行快速演示,否则不建议使用此属性),或者使用上述的RelativeSource Binding
来查找该属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.