Question

I have following control in XAML based window that shows a vector image "Logo":

<ContentControl Margin="10" Content="{StaticResource Logo}" Height="45"></ContentControl>

And it links to "Logo" vector image data in a resource XAML file:

<Viewbox x:Key="Logo" x:Shared="False">
    <Canvas  Height="256" Width="256">
        <Path  Fill="#46D42C">
            <Path.Data>
                <PathGeometry Figures="m 71.72 ... <data removed by me to post on stackoverflow> .... 71.72 0.00 z" FillRule="NonZero"/>
            </Path.Data>
        </Path>
        </Path>
    </Canvas>
</Viewbox>

I want to know how can I change the code in main window to show a JPG file by linking to a jpg file path and not link to a vector image data in resource file.

Was it helpful?

Solution

Add a JPG file to your resources and set the build action to "Resource". Then put the following code into the Viewbox. The resource declaration can also be transfered into a resource dictionary.

<Viewbox>
    <Grid>
        <Grid.Resources>
            <BitmapImage
                x:Key="image"
                UriSource=".\Resources\art.jpg" />
        </Grid.Resources>
        <Canvas>
            <Image
                Source="{StaticResource ResourceKey=image}" />
        </Canvas>
    </Grid>
</Viewbox>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top