2013-08-10 2 views
5

단추 안에 TextBlock을 포함하는 WPF에서 간단한 사용자 정의 컨트롤을 만들고 있습니다. UserControl 종속성 속성 디자인 타임

<UserControl x:Class="WpfExpansion.MyButton"..... > 
    <Grid > 
     <Button Background="Transparent" > 
      <TextBlock Text="{Binding Path=Text}"/> 
     </Button> 
    </Grid> 
</UserControl> 

또한 "텍스트"종속성 속성

.

<MyButton Text="Test" /> 

문제는 비주얼 스튜디오의 디자인이 변경되지 않는다는 것입니다,하지만 런타임 작동합니다

public partial class MyButton : UserControl 
{ 
    public MyButton() 
    { 
     InitializeComponent(); 
     this.DataContext = this;   
    } 

    public string Text 
    { 
     get { return (string)GetValue(TextProperty); } 
     set { SetValue(TextProperty, value); } 
    } 
    public static readonly DependencyProperty TextProperty = 
     DependencyProperty.Register("Text", typeof(string), typeof(MyButton), new PropertyMetadata(string.Empty)); 

} 

그리고는 나는이 같은 UserControl을 사용합니다.

무엇이 잘못 되었나요?

는 또한 성공없이 UC 정의 내부
DataContext="{Binding RelativeSource={RelativeSource Self}}" 

을 시도했다.

답변

4

아래 같은 AffectsRender를 지정 PropertyMetadata 대신 FrameworkPropertyMetadata를 사용해보십시오, 다음 를 다시 시작 비주얼 스튜디오 :

public static readonly DependencyProperty TextProperty = 
    DependencyProperty.Register("Text", typeof(string), typeof(MyButton), 
     new FrameworkPropertyMetadata(string.Empty, 
      FrameworkPropertyMetadataOptions.AffectsRender)); 

MSDN Documentation에 대한 FrameworkPropertyMetadataOptions.AffectsRender

이외의 렌더링 또는 레이아웃 구성의 일부 측면을 (말한다 measure 또는 arrange)은이 종속성 속성에 대한 값 변경의 영향을받습니다. 다른 경우를 들어

는 등

+2

대, AffectsMeasure, AffectsArrange 같은 옵션이 있습니다! 처음에는 이것이 작동하지 않는 것 같아 Visual Studio를 닫고 열면 이제는 정상적으로 작동합니다. 많은 감사. – Guilherme

관련 문제