View Model requires information about control in xaml, MVVM way to do this?
<p>From what I understand of MVVM this is the wrong idea but I'd like to know if that is actually true and if so how to correctly achieve what I am trying to, or otherwise I'd like help on doing it.</p>

<p>I have a ConnectorViewModel which contains a class FullyCreatedConnectorInfo that stores the 'anchor point' of where a node should drop. To calculate this I require the following function:</p>

<pre><code>public static Point GetPointForConnector(DesignerCanvas canvas, Connector source)
{
    Point p = source.TranslatePoint(new Point(0, 0), canvas);
    p.X += source.Width / 2.0d;
    p.Y += source.Height / 2.0d;
    return p;
}
</code></pre>

<p>Where 'connector' is a UserControl of the connection point, DesignerCanvas is a Canvas which the connector resides in.</p>

<p>This function is called by the ConnectorViewModel to calculate a bezier curves start and end points which is binded to a property from the ConnectorViewModel.</p>

<p>I can make this work fine when the user is dragging points around as the events which end up getting called go through those controls so I have access to the connectors and canvas at the relevant points.</p>

<p>My issue is if I want to programatically create a ConnectorViewModel from say MainWindow.xaml.cs I require access to the connector control and the canvas. I can do something like this for the designer canvas:</p>

<pre><code>&lt;s:DesignerCanvas Loaded="DesignerCanvas_Loaded"
</code></pre>

<p>Then in the DesignerCanvas_Loaded function I can create a static reference to the designer canvas, since there is only one it sort of becomes a singleton. I'd really rather not do this however.</p>

<p>However for the Connector it's not so easy as it's defined using Data templates:</p>

<pre><code>&lt;DataTemplate DataType="{x:Type local:NodeViewModel}"&gt;
    &lt;local2:Node/&gt;
&lt;/DataTemplate&gt;
</code></pre>

<p>So I'm not sure how I can find 'Node' from 'NodeViewModel'.</p>

<p>Even if I could figure it out I don't think this follows MVVM correctly since a ViewModel should not have to know what a Control has in it.</p>

<p>If it does abide by MVVM or doing it another way is too difficult and I have to do it this way I'd like help on how to do it?</p>

<p>The code is adapted from this sample: <a href="http://www.codeproject.com/Articles/484616/MVVM-Diagram-Designer" rel="nofollow">http://www.codeproject.com/Articles/484616/MVVM-Diagram-Designer</a></p>