2014-01-29 3 views
0

CornerRadius 값을 바인딩하고 싶습니다.CornerRadius에서 Dependency 속성으로 바인딩

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을 사용하여 속성을 찾을 수 있습니다.

관련 문제