【发布时间】:2015-12-02 01:07:31
【问题描述】:
我有自己的UserControl
<local:MyUserControl MyProperty="{Binding myString}"/>
我将myString 绑定到它。现在我想在我的UserControl 中使用它。我在UserControl 中定义了DependencyProperty:
public string MyProperty
{
get { return (string)GetValue(MyPropertyProperty); }
set
{
Debug.WriteLine(value);//writes nothing, null
SetValue(MyPropertyProperty, value);
}
}
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(MyUserControl), new PropertyMetadata(null));
我做错了什么?我想用这个字符串做一些事情。但它始终为空。
【问题讨论】:
-
像这样尝试RelativeSource:stackoverflow.com/questions/5077377/usercontrols-datacontext
标签: c# xaml windows-phone-8.1 uwp