In my Silverlight MVVM application, in the code-behind of a view, I set the DataContext to a viewmodel as such:
this.DataContext = new MyViewModel();
However, I need to bind one control in the view to another in the same view. So, I need to set the DataContext of the control where I’m adding the binding to the view itself.
After browsing around, it seems like the definitive way of doing this in WPF is by adding:
DataContext="{Binding
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}
to the control.
However the AncestorType property does not exist in Silverlight 4. Is there an equivalent, definitive line of code that is used for this scenario in Silverlight? I haven’t run into any website or answer that shows the best practice for this.
This may help me answer an earlier question where I am trying to bind a custom control and property within a view.
Can you explain what do you want to do?
Probably you can use
ElementNamefromBindingclassHere is a sample example from msdn page: