【发布时间】:2016-01-19 07:23:24
【问题描述】:
我有具有 TextInUserControl 属性的用户控件。
UserControl1.cs
public static readonly DependencyProperty TextInUserControlProperty =
DependencyProperty.Register("TextInUserControl",
typeof(string),
typeof(UserControl1));
public string TextInUserControl
{
get { return (string)GetValue(TextInUserControlProperty); }
set { SetValue(TextInUserControlProperty, value); }
}
我可以在我的主窗口中绑定到这个属性,当我在我的主窗口中更改这个属性时,它也会在用户控件中更新。这意味着正在完美读取来自源的属性更改。但是如何更改主窗口的此属性以在用户控件内部(到源)?
我正在尝试做但没有工作的示例:
public UserControl1()
{
InitializeComponent();
TextInUserControl = "test";
//or something like SetValue(TextInUserControlProperty, "test");
}
【问题讨论】:
标签: c# wpf xaml data-binding user-controls