Displaying xaml resources dynamically?
- by Robert
I used Mike Swanson's illustrator to xaml converter 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.
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.
<UserControl.Resources>
<DataTemplate x:Key="PrimTrafo" DataType="{x:Type l:Windings}">
<Frame Source="{Binding}" x:Name="PART_Image" NavigationUIVisibility="Hidden">
<Frame.LayoutTransform>
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
</Frame.LayoutTransform>
</Frame>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding}" Value="PrimD">
<Setter TargetName="PART_Image" Property="Source" Value="Resources\PrimD.xaml" />
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="PrimY">
<Setter TargetName="PART_Image" Property="Source" Value="Resources\PrimY.xaml" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</UserControl.Resources>
<!--The contentcontrol that holds the datatemplate defined above-->
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0" Content="{Binding PrimaryWinding}" ContentTemplate="{StaticResource PrimTrafo}"/>
</Grid>
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.
Is a Frame the wrong class to hold the drawings?
Should I use the ScaleTransform class to resize the drawing to the size of the cell? And how can I do that dynamically?