I have a WPF CustomControl with a depdendency property called SelectedRange.
In an application in XAML the binding is set like this:
SelectedRange="{Binding Source={StaticResource ResourceKey=MainWindow},
Path=GlobalXRange, Mode=TwoWay}"
I find in the code that the BindingExpression is getting overwritten (set to null). I can determine this with this code:
public IRange SelectedRange
{
get { return (IRange)GetValue(SelectedRangeProperty); }
set
{
SetValue(SelectedRangeProperty, value);
Binding b = BindingOperations.GetBinding(this, SelectedRangeProperty);
BindingExpression be =
BindingOperations.GetBindingExpression(this, SelectedRangeProperty);
if (be == null)
{
Console.WriteLine("Binding expression is null!");
}
}
}
It turns out the BindingExpression is null after the application starts.
So my question is - how can I debug why this BindingExpression is null - e.g. it is set in XAML how can I find out where it is being set to null?
Note: There are no binding errors in the output console
SelectedRangewill not be called if use binding. WPF will bind directly to yourSelectedRangePropertyand callSetValue(...)directly on itnull? I've just created my simleUserControlwith oneDependancyPropertythat is bound inMainWindowand when I checkBindingExpressioninPropertyChangedCallbackit's nevernullSetValueandSetCurrentValueand, unfortunately, know all to well that SilverLight is constant workaround something that already exists in WPF