I have a custom property that works perfectly, except when it's bound to an object.
The reason is that once the following code is executed:
base.SetValue(ValueProperty, value);
... then my control is no longer bound. I know this because calling:
base.GetBindingExpression(ValueProperty);
... returns the binding object perfectly - UNTIL I call base.SetValue. So my question is, how do I pass the new "value" on to the object that I'm bound to?
EDIT: Here's the code...
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);
}
}
As you can see, it's simple, boilerplate, "Microsoft sample" code.
EDIT 2: Here's the code for the binding...
// Apparently, not showing this line of code here has some people confused...
this.DataContext = new SomeClassWithAPropertyCalledNumericValue();
<my:NumericTextBox Value="{Binding NumericValue}" />
Again... simple.