Wpf 如何绑定用户';将控件标签内容添加到自定义依赖项属性
我正在尝试将用户的控件标签内容绑定到自定义依赖项属性。我的依赖属性是:Wpf 如何绑定用户';将控件标签内容添加到自定义依赖项属性,wpf,binding,dependency-properties,Wpf,Binding,Dependency Properties,我正在尝试将用户的控件标签内容绑定到自定义依赖项属性。我的依赖属性是: public static readonly DependencyProperty DayProperty = DependencyProperty.Register("Day", typeof(string), typeof(MultiSlider), new UIPropertyMetadata("some")); public string Day { get {
public static readonly DependencyProperty DayProperty =
DependencyProperty.Register("Day", typeof(string), typeof(MultiSlider), new UIPropertyMetadata("some"));
public string Day
{
get { return (string)GetValue(DayProperty); }
set { SetValue(DayProperty, value); }
}
我想买点像这样的东西
<Label Content="{TemplateBinding Day}"/>
在我的用户控件内部。通过添加以下内容解决:
DataContext="{Binding RelativeSource={RelativeSource Self}}"
到我的用户控件,然后只执行以下操作:
<Label Content="{Binding Path=Day}"/>
您可以将您的解决方案作为答案发布并接受。我想这会提高问答的质量。克莱门斯,谢谢你的建议。我无法做到这一点,因为声誉价值很低,现在我已经足够了:)