簡體   English   中英

將CornerRadius綁定到依賴屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM