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}}"
을 시도했다.
대, AffectsMeasure, AffectsArrange 같은 옵션이 있습니다! 처음에는 이것이 작동하지 않는 것 같아 Visual Studio를 닫고 열면 이제는 정상적으로 작동합니다. 많은 감사. – Guilherme