Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying xaml resources dynamically?
    text
    copied!<p>I used Mike Swanson's <a href="http://www.mikeswanson.com/xamlexport/" rel="nofollow noreferrer">illustrator to xaml converter</a> to convert some of my images to xaml. The convert creates a viewbox that contains the image. These viewboxes I made resource files in my program. </p> <p>The code below shows what I'm trying to do: I have a viewmodel that has an enum variable called PrimaryWinding of type Windings. The values PrimD and PrimY of the enum select the respective PrimD and PrimY xaml files in the resources.</p> <pre><code>&lt;UserControl.Resources&gt; &lt;DataTemplate x:Key="PrimTrafo" DataType="{x:Type l:Windings}"&gt; &lt;Frame Source="{Binding}" x:Name="PART_Image" NavigationUIVisibility="Hidden"&gt; &lt;Frame.LayoutTransform&gt; &lt;ScaleTransform ScaleX="0.5" ScaleY="0.5"/&gt; &lt;/Frame.LayoutTransform&gt; &lt;/Frame&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding}" Value="PrimD"&gt; &lt;Setter TargetName="PART_Image" Property="Source" Value="Resources\PrimD.xaml" /&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding}" Value="PrimY"&gt; &lt;Setter TargetName="PART_Image" Property="Source" Value="Resources\PrimY.xaml" /&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/UserControl.Resources&gt; &lt;!--The contentcontrol that holds the datatemplate defined above--&gt; &lt;Grid &gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="2*"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="2*"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="1*"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ContentControl Grid.Column="0" Content="{Binding PrimaryWinding}" ContentTemplate="{StaticResource PrimTrafo}"/&gt; &lt;/Grid&gt; </code></pre> <p>This code works. Only I can't resize the drawings to the size of the grid cell. I added the ScaleTransform class to resize the image.<br> Is a Frame the wrong class to hold the drawings?<br> Should I use the ScaleTransform class to resize the drawing to the size of the cell? And how can I do that dynamically? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload