Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBlock.GetBindingExpression returning NULL

Tags:

c#

.net

wpf

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?

like image 693
blue18hutthutt Avatar asked Aug 20 '12 06:08

blue18hutthutt


1 Answers

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.

like image 92
Dennis Avatar answered Sep 30 '22 19:09

Dennis