本文介绍了当页面的数据文本用于其他绑定时,如何绑定到WPF依赖属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当页面的数据标签用于其他绑定时,如何绑定到WPF依赖属性? (简单问题)
How to bind to a WPF dependency property when the datacontext of the page is used for other bindings? (Simple question)
推荐答案
需要设置元素的数据文本。
The datacontext of the element needed to be set.
XAML:
<Window x:Class="WpfDependencyPropertyTest.Window1" x:Name="mywindow">
<StackPanel>
<Label Content="{Binding Path=Test, ElementName=mywindow}" />
</StackPanel>
</Window>
C#:
public static readonly DependencyProperty TestProperty =
DependencyProperty.Register("Test",
typeof(string),
typeof(Window1),
new FrameworkPropertyMetadata("Test"));
public string Test
{
get { return (string)this.GetValue(Window1.TestProperty); }
set { this.SetValue(Window1.TestProperty, value); }
}
另请参阅相关问题:
这篇关于当页面的数据文本用于其他绑定时,如何绑定到WPF依赖属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!