0

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)
Hamid
  • 1,099
  • 3
  • 22
  • 37
  • 1
    We can't help if you don't show us your code (XAML and corresponding code behind). – Nuffin Jan 25 '12 at 08:21
  • 1
    People, people! Never ask for "source code." Always ask for the ***minimum amount of code*** that covers the question. In this case, we need to see the xaml for the control that has the binding you wish to retrieve (not the whole window!) and the Loaded event handler. –  Jan 25 '12 at 12:44

2 Answers2

1

If you don't use {Binding ... in XAML you can't use GetBindingExpression() method. In your case you set value instead of binding. You need to use cb1.GetValue(LookUp.LookUpItemsSourceProperty) instead.

zmechanic
  • 1,842
  • 21
  • 27
1

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}}
Akash Kava
  • 39,066
  • 20
  • 121
  • 167