Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

Get Binding Value Programmatically

$
0
0

I want to get a value from the DataContext based on the control's binding. I can already do this. This is an example with a ComboBox. In this sample I get the value of the property that is bound to the SelectedItem property of the ComboBox. This works well.

            DataContextChanged += (s, e) =>
            {
                var selectedItemBindingExpression = GetBindingExpression(SelectedItemProperty);

                object selectedItem;
                if (DataContext != null)
                {
                    selectedItem = ReflectionUtils.GetChildObjectProperty(DataContext, selectedItemBindingExpression.ParentBinding.Path.Path, true);
                }
                else
                {
                    selectedItem = null;
                }

                TempSelectedItem = selectedItem;
            };

Note: The GetChildObjectProperty method recurses in to the properties on the object and gets the ultimate value using reflection.

In essence, what I am doing here is the same thing that binding does. However, I want to know if there is a way I can get this value using Silverlight's binding engine... Is there a way I can get this value without manually recursing through the properties and using my own logic to get the value? I mean my code won't even work if there is a converter involved. Please let me know if there is some way I can invoke Silverlight's binding engine to do this.


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>