How to retrieve a specific dataBinding from MultiBindingExpression?
In my application I retrieve binding from one object and assign it to another. And some objects has MultiBinding instead. And I want to retrieve a specific binding. How do I do that?
For non multi-bindings I use the following code:
Label lbl = (Label)sender;
BindingExpression bindingExpression = lbl.GetBindingExpression.(Label.ContentProperty);
Binding parentBinding = bindingExpression.ParentBinding;
path = parentBinding.XPath.ToString();
label.SetBinding(Label.Conten开发者_JAVA技巧tProperty, parentBinding);
I have figured it out. I couldn't get binding directly from label, but I was able to use BindingOperations.GetMultiBindingExpression static method to retrieve MultiBindingExpression and then getting the right Binding.
Here is code for that:
MultiBindingExpression multiBindingExpression = BindingOperations.GetMultiBindingExpression(lbl, Label.ContentProperty);
Binding parentBinding = ((BindingExpression)multiBindingExpression.BindingExpressions[1]).ParentBinding;
精彩评论