我有一個完美的自定義屬性,除非它綁定到一個對象。在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