blue18hutthutt
blue18hutthutt

Reputation: 3243

TextBlock.GetBindingExpression returning NULL

The following is returning NULL for me, any idea why?

MultiBinding collectionRange = new MultiBinding();
collectionRange.Bindings.Add(new Binding("CurrentPosition") { Source = View });
collectionRange.Bindings.Add(new Binding("Count") { Source = View });
collectionRange.StringFormat = "{0} of {1}";
tbFooter.SetBinding(TextBlock.TextProperty, collectionRange);
var x = tbFooter.GetBindingExpression(TextBlock.TextProperty);

The MultiBinding is fine - the properties are valid and it renders on the UI ..I just can't seem to grab the binding expression (x is always NULL)

Am I using this method wrong?

Upvotes: 8

Views: 5881

Answers (1)

Dennis
Dennis

Reputation: 37770

This method is really just a convenience wrapper around the BindingOperations.GetBindingExpression method. GetBindingExpression passes the current instance and the dp parameter to BindingOperations.GetBindingExpression.

If your binding is a MultiBinding, use BindingOperations.GetMultiBinding.

See "Remarks" section and notes in "Examples" section here.

Upvotes: 16

Related Questions