title: How to reference an existing DataTemplate in a ViewBox?
body: <p>In one Resource Dictionary file I have a <code>DataTemplateDictionary</code> with different DataTemplates. Let us say there is a DataTemplateA, and a DataTemplateB which are unique shapes. For DataTemplateC, I want to re-use DataTemplateA but it will be scaled down and used as a preview. I've read that I should use a ViewBox but after several attempts it has not worked.
  Here is a snippet of DataTemplateA:</p>
  
  <pre><code>&lt;DataTemplate x:Key="DataTemplateA"&gt;
      &lt;Grid ShowGridLines="False" Margin="0,0,0,0"  Visibility="Visible" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
          &lt;Grid.ColumnDefinitions&gt;                        
              &lt;ColumnDefinition Width="174" /&gt;
              &lt;ColumnDefinition Width="126"/&gt;                        
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Canvas&gt;
              &lt;Path Grid.RowSpan="2" Grid.ColumnSpan="2" Fill="#bcc5d2" Stroke="#5075ba" StrokeThickness="1" 
              Data="M 11,0 287,0 
                  Q 299,0 299,11
                  L 299,11 299,87
                  Q 299,99 287,99
                  L 287,99 11,99
                  Q 0,99 0,87
                  L 0,87 0,11
                  Q 0,0 11,0 Z"
              Margin="0,0,0,0" Stretch="UniformToFill" /&gt;
          &lt;/Canvas&gt;                   
      &lt;/Grid&gt;            
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Here is a snippet of DataTemplateC:</p>
  
  <pre><code>    &lt;DataTemplate x:Key="DataTemplateC"&gt;
          &lt;go:NodePanel Sizing="Fixed" go:Part.SelectionAdorned="True" ToolTip="Breaker Left Align" go:Node.Location="{Binding Path=Data.Location, Mode=OneWay}"&gt;
              &lt;Viewbox Width="50" Height="30"&gt;
                  &lt;Rectangle  x:Name="FusedCB_VIcon" 
                         RadiusX="0" RadiusY="0" Stroke="Black" StrokeThickness="0"
                         Fill="{StaticResource DataTemplateA}"&gt;
                  &lt;/Rectangle&gt;
              &lt;/Viewbox&gt;               
          &lt;/go:NodePanel&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>As you can see I am trying to fill the rectangle with an existing DataTemplate but this does not work. I have also tried the following:</p>
  
  <pre><code>    &lt;DataTemplate x:Key="DataTemplateC"&gt;
          &lt;go:NodePanel Sizing="Fixed" go:Part.SelectionAdorned="True" ToolTip="Breaker Left Align" go:Node.Location="{Binding Path=Data.Location, Mode=OneWay}"&gt;
              &lt;Viewbox Width="50" Height="30"&gt;
                  &lt;my:DataTemplateA/&gt;
              &lt;/Viewbox&gt;                
          &lt;/go:NodePanel&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>I am just unsure of how to do such simple task. Any advice or help is highly appreciated, or <strong>is there another method I should look into?</strong></p>
  
  <p>Here is my xaml file, DataTemplateA is my BreakerLA and DataTemplateC is my sBreakerLA:</p>
  
  <p></p>
  
  <pre><code>&lt;ResourceDictionary.MergedDictionaries&gt;
      &lt;ResourceDictionary Source="GoXamStyleDictionary.xaml" /&gt;
      &lt;ResourceDictionary Source="ElevationImages.xaml" /&gt;
  &lt;/ResourceDictionary.MergedDictionaries&gt;
  
  &lt;go:DataTemplateDictionary x:Key="OneLineEditorDiagramTemplateDictionary"&gt;
      &lt;DataTemplate x:Key="Breaker"&gt;
          &lt;go:NodePanel Sizing="Fixed" go:SpotPanel.Main="True" go:Part.SelectionAdorned="True" ToolTip="Breaker" go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"&gt;
              &lt;Rectangle Width="50" Height="50" x:Name="CB_VIcon"
                         RadiusX="0" RadiusY="0" Stroke="Transparent" StrokeThickness="0"
                         Cursor="Hand" Fill="{StaticResource CB_V}"&gt;
              &lt;/Rectangle&gt;
              &lt;TextBlock Style="{StaticResource TextBlockStyle}"
                         Text="{Binding Path=Data.Text, Mode=TwoWay}" /&gt;
          &lt;/go:NodePanel&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate x:Key="BreakerLA"&gt;
          &lt;Border BorderThickness="1" BorderBrush="{Binding Path=Data.Held, Converter={StaticResource heldConverter}}"
                  Background="Transparent" x:Name="BreakerIcon"
                  Width="Auto" Height="Auto"
                  TouchDown="touchDownHandler" TouchUp="touchUpHandler"
                  TouchMove ="touchMoveHandler" TouchLeave="touchLeaveHandler"
                  Stylus.IsPressAndHoldEnabled="False"
                  go:Node.Movable="False"
                  go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}" 
                  go:Node.LocationSpot="TopLeft"
                  go:Part.SelectionAdorned="True"
                  go:Part.SelectionElementName="BreakerIcon"
                  go:Part.SelectionAdornmentTemplate="{StaticResource NodeSelectionAdornmentTemplate}"
                  go:Part.Resizable="False"
                  go:Part.ResizeElementName="BreakerIcon"
                  go:Part.ResizeAdornmentTemplate="{StaticResource NodeResizeAdornmentTemplate}"
                  go:Node.RotationAngle="{Binding Path=Data.Angle, Mode=TwoWay}"
                  go:Part.Rotatable="False"
                  go:Part.DragOverSnapEnabled="True"
                  go:Part.DragOverSnapCellSpot="TopLeft"
                  go:Part.RotateAdornmentTemplate="{StaticResource NodeRotateAdornmentTemplate}"&gt;
              &lt;!--Breaker info--&gt;
              &lt;Grid ShowGridLines="False" Margin="0,0,0,0"  Visibility="Visible" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
                  &lt;Grid.ColumnDefinitions&gt;                        
                      &lt;ColumnDefinition Width="174" /&gt;
                      &lt;ColumnDefinition Width="126"/&gt;                        
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Canvas&gt;
                      &lt;Path Grid.RowSpan="2" Grid.ColumnSpan="2" Fill="#bcc5d2" Stroke="#5075ba" StrokeThickness="1" 
                      Data="M 11,0 287,0 
                          Q 299,0 299,11
                          L 299,11 299,87
                          Q 299,99 287,99
                          L 287,99 11,99
                          Q 0,99 0,87
                          L 0,87 0,11
                          Q 0,0 11,0 Z"
                      Margin="0,0,0,0" Stretch="UniformToFill" /&gt;
                  &lt;/Canvas&gt;
                  &lt;!--Data Labels--&gt;
                  &lt;StackPanel Grid.Row="0" Grid.Column="0" Margin="0,0,12,0"  HorizontalAlignment="Right" VerticalAlignment="Center"&gt;
                      &lt;TextBlock Text="{Binding Path=Data.OneLineBreakerData.BreakerName, Mode=TwoWay}" FontFamily="XX Inspira Medium" 
                                 FontSize="16px" Foreground="Black" HorizontalAlignment="Right" FontWeight="DemiBold"
                                  LineStackingStrategy="BlockLineHeight" LineHeight="16"/&gt;
                      &lt;TextBlock Text="{Binding Path=Data.OneLineBreakerData.BreakerCompartmentNo, Mode=TwoWay}" FontFamily="XX Inspira Regular"
                                 FontSize="15px" Foreground="Black" HorizontalAlignment="Right"
                                  LineStackingStrategy="BlockLineHeight" LineHeight="18"/&gt;
                      &lt;TextBlock Text="{Binding Path=Data.OneLineBreakerData.PTRating, Mode=TwoWay}" FontFamily="XX Inspira Regular" 
                                 FontSize="15px" Foreground="Black" HorizontalAlignment="Right"
                                  LineStackingStrategy="BlockLineHeight" LineHeight="16"/&gt;
                  &lt;/StackPanel&gt;
                  &lt;!--Breaker Node and Icon Info--&gt;
                  &lt;Grid ShowGridLines="False" VerticalAlignment="Top" HorizontalAlignment="Right" Grid.Column="1" Height="98" Margin="0,1,12,0"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="52" /&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;go:SpotPanel MouseEnter="Node_MouseEnter" MouseLeave="Node_MouseLeave" Grid.Column="0" Margin="-12,0,0,0"&gt;
                          &lt;go:NodePanel Sizing="Fixed" go:SpotPanel.Main="True" Width="52" Height="90"  Margin="0,4,0,0" VerticalAlignment="Top"&gt;
                              &lt;Rectangle x:Name="CB_VIcon" RadiusX="0" RadiusY="0" Stroke="Transparent" StrokeThickness="0" Margin="0,0,0,0"
                                  Cursor="Hand" Fill="{StaticResource CB_V}" SnapsToDevicePixels="True"&gt;
                              &lt;/Rectangle&gt;
                      &lt;/go:SpotPanel&gt;
                      &lt;Grid Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,0" HorizontalAlignment="Center" Height="100"&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="*" /&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;TextBlock Grid.Row="0" Text="TRIP" Margin="0,0,0,0" Foreground="#df2026" FontSize="16" 
                                         TextWrapping="NoWrap" FontFamily="XX Inspira Medium" Height="Auto" VerticalAlignment="Center" HorizontalAlignment="Center" /&gt;
                          &lt;Rectangle x:Name="Info_Icon" RadiusX="0" RadiusY="0" Stroke="Transparent" StrokeThickness="0" Margin="0,0,0,7" HorizontalAlignment="Center"
                                     Height="30" Width="30" VerticalAlignment="Bottom"  Fill="{StaticResource info_Icon}" SnapsToDevicePixels="True"&gt;
                          &lt;/Rectangle&gt;
                      &lt;/Grid&gt;
                  &lt;/Grid&gt;
              &lt;/Grid&gt;
          &lt;/Border&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate x:Key="sBreakerLA"&gt;
          &lt;go:NodePanel Sizing="Fixed" go:Part.SelectionAdorned="True" ToolTip="Breaker Left Align" go:Node.Location="{Binding Path=Data.Location, Mode=OneWay}"&gt;
              &lt;Viewbox Width="50" Height="30"&gt;
                  &lt;ContentControl Content="." ContentTemplate="{StaticResource BreakerLA}" /&gt;
              &lt;/Viewbox&gt;
          &lt;/go:NodePanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/go:DataTemplateDictionary&gt;
  </code></pre>
  
  <p></p>
  
  <p>And this is the function that grabs the DataTemplate:</p>
  
  <pre><code>private void CB_VerticalSelection(Node brkNode)
  
  {
          editorDiagram.StartTransaction("DroppedBreaker");
          OneLineModelData brkData = brkNode.Data as OneLineModelData;
          System.Console.WriteLine("Test");
          editorDiagram.GroupTemplate = resGroupTempdict["PaletteGroupTemplate"] as DataTemplate;
          //editorDiagram.NodeTemplateDictionary = resPaletteDictionary["OneLinePaletteTemplateDictionary"] as DataTemplateDictionary;
          editorDiagram.Model.RemoveNode(brkData);
          // Populates the pop-up with the following nodes
          editorDiagram.Model.AddNode(new OneLineModelData()
          { Key = "0", Text = "", Category = "sBreakerLA", SubGraphKey = "BG1",
              Location = new System.Windows.Point(nodeDropLocation.X, nodeDropLocation.Y + 20) });
          editorDiagram.CommitTransaction("DroppedBreaker");
      }
  </code></pre>
  
  <p>Error I am getting:
  <a href="https://i.stack.imgur.com/VY2QR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VY2QR.png" alt="enter image description here"></a></p>