【发布时间】:2013-12-10 13:06:44
【问题描述】:
我有一个包含文本框的用户控件,并在用户控件中创建了一个获取/设置来获取/设置文本框的文本属性。
public class OpenFileControl : UserControl
{
StackPanel sp;
public TextBox tb;
public string Text { get { return tb.Text; } set { tb.Text = value; } }
然后我想稍后根据绑定设置此值 -
<gX3UserControls:OpenFileControl Text="{Binding Value}" />
但我得到以下异常 不能在“OpenFileControl”类型的“文本”属性上设置“绑定”。 “绑定”只能在 DependencyObject 的 DependencyProperty 上设置。
经过一番调查,似乎 Text 需要是一个依赖属性,但如果我这样做,我无法弄清楚如何将值传递给文本框。
我该如何解决这个问题。
【问题讨论】: