我有一个完美的自定义属性,除非它绑定到一个对象。在WPF中,如何更新我的自定义属性绑定的对象?
的原因是,一旦下面的代码被执行:
base.SetValue(ValueProperty, value);
...然后我的控制不再约束。我知道这是因为呼吁:
base.GetBindingExpression(ValueProperty);
...完全返回绑定对象 - UNTIL我打电话base.SetValue。所以我的问题是,我如何将新的“值”传递给我所绑定的对象?
编辑:下面的代码...
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(decimal?), typeof(NumericTextBox));
public decimal? Value
{
get
{
return (decimal?)base.GetValue(ValueProperty);
}
set
{
base.SetValue(ValueProperty, value);
}
}
正如你所看到的,这很简单,样板, “微软示例” 的代码。
编辑2:下面是绑定代码...
// Apparently, not showing this line of code here has some people confused...
this.DataContext = new SomeClassWithAPropertyCalledNumericValue();
<my:NumericTextBox Value="{Binding NumericValue}" />
再次...简单。
您能告诉我们(a)您的自定义属性和(b)绑定的代码吗? – Heinzi 2010-04-14 17:12:38
当然...现在加入它。 – 2010-04-14 17:17:21
答案就像做TwoWay绑定和实现属性更改通知一样简单吗? – Ragepotato 2010-04-14 17:25:17