Here is my situation. I have a View and a ViewModel. The view's DataContext is set to the ViewModel. Due to the use of a 3rd party control, I am forced to put some code in the code-behind. In the code-behind I create an object called StraightConnectorTool.
In my View, I need to bind to this object. If the View's DataContext is set in the code-behind:
DataContext = this;
The following binding works fine.
<BarItemToolBehavior ActiveTool="{Binding ActiveTool, ElementName=diagram, Mode=TwoWay}"
Tool="{Binding StraightConnectorTool}"/>
Where diagram is the name of the 3rd party control on the View and ActiveTool is one of it's properties.
However, if the View's DataContext is set to the ViewModel, the binding doesn't work. I'm stuck trying to figure out how to bind to the view when it's DataContext is set to the ViewModel. Any ideas?
this.DataContext = this;
is the cancer of WPF MVVM. This article explains why You'll note it's kinda long, but so is chemo. – user1228