I'm trying to call the GetBindingExpression method in the Loaded event, but it always returns null
.
Is this expected behavior, or am I doing something wrong? If it is expected, after what event do binding expressions become available?
I just create custom control
public partial class LookUp : ComboBox
public static readonly DependencyProperty LookUpItemsSourceProperty =
DependencyProperty.Register("LookUpItemsSource"
, typeof(IEnumerable)
, typeof(LookUp)
, new PropertyMetadata(OnItemsSourcePropertyChanged));
public IEnumerable LookUpItemsSource
{
get
{
return this.GetValue(LookUpItemsSourceProperty) as IEnumerable;
}
set
{
this.SetValue(LookUpItemsSourceProperty, value);
}
}
And use this control in xaml
<Controls:LookUp Name="cb1" LookUpItemsSource="{x:Static Helper:DataManager.CycleLookUpData}"
Now i want to get binding expression when control initialized that method return null:
cb1.GetBindingExpression(LookUp.LookUpItemsSourceProperty)
x:static will set the value of key, it is not binding expression. You will have to use,
{Binding CycleLookUpData, source={x:static Helper:DataManager}}