WPF中的DependencyProperty和UserControl
我创建了一个UserControl,在两个网格行中有一个标签和一个矩形。 我添加了属性WPF中的DependencyProperty和UserControl,wpf,user-controls,customproperty,Wpf,User Controls,Customproperty,我创建了一个UserControl,在两个网格行中有一个标签和一个矩形。 我添加了属性 public string SetText { get { return (string)GetValue(mLabel.ContentProperty); } set { SetValue(mLabel.ContentProperty, value); } } 财产的使用 <local:PlayerMiniImage S
public string SetText
{
get
{
return (string)GetValue(mLabel.ContentProperty);
}
set
{
SetValue(mLabel.ContentProperty, value);
}
}
财产的使用
<local:PlayerMiniImage SetText="Player 1" ...
如果定义用户控件
<UserControl x:Class="...">
<Border>
<!-- ... -->
</Border>
</UserControl>
并将标签绑定到它:
<Label Content="{Binding LabelContent, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
如何在PlayerMiniImage中绑定SetText?
<Label Content="{Binding LabelContent, RelativeSource={RelativeSource AncestorType=UserControl}}"/>