Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set wpf's Image Source property to canvas instead of image url?

Tags:

c#

wpf

<Canvas x:Key="myCanvas" 
    MinHeight="30" MinWidth="30" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" >
    <Path Data="F1M1737.61,7339.85C1720.49,7342.44 1709.83,7334.36 1709.83,7334.36  1701.44,7341.47 1682.84,7340.17 1682.84,7340.17 1682.66,7388.31 1709.83,7397.03 1709.83,7397.03 1741.17,7386.37 1737.61,7339.85 1737.61,7339.85 M1709.54,7386.88C1707.5,7386.88 1705.85,7385.23 1705.85,7383.18 1705.85,7381.14 1707.5,7379.49 1709.54,7379.49 1711.58,7379.49 1713.23,7381.14 1713.23,7383.18 1713.23,7385.23 1711.58,7386.88 1709.54,7386.88 M1712.37,7367.58C1712.37,7367.58 1712.28,7370.72 1710.94,7372.06 1710.94,7372.06 1709.33,7373.48 1707.54,7371.61 1707.54,7371.61 1707.09,7370.31 1706.47,7366.75L1705.48,7352.56 1705.48,7348.72C1705.48,7348.72 1705.59,7345.14 1709.61,7344.51 1709.61,7344.51 1713.36,7344.34 1713.53,7348.27 1713.53,7348.27 1713.98,7352.56 1712.37,7367.58" Stretch="Uniform" Fill="#FFF1A603" Width="26" Height="26" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
        <Path.RenderTransform>
            <TransformGroup>
                <TransformGroup.Children>
                    <RotateTransform Angle="0" />
                    <ScaleTransform ScaleX="1" ScaleY="1" />
                </TransformGroup.Children>
             </TransformGroup>
        </Path.RenderTransform>
    </Path>
</Canvas>

How can i set wpf's Image Source property to canvas instead of image url ?

Something like this

<Image Source"{StaticResource MyCanvas}"/>
like image 872
Alex David Avatar asked Mar 20 '23 00:03

Alex David


2 Answers

You seem to be somewhat confused... you are asking if we can set the Image.Source property, which is of type ImageSource to a Canvas object. Well I'm pretty sure that you would know that you simply can't do that because a Canvas is not a ImageSource.

However, what I think you are actually wanting to find out is how to display your Canvas from your Resources section. If that is what you are after, then there is a much simpler way to do that... you can just display it in a ContentControl like this:

<ContentControl Content="{StaticResource myCanvas}" />
like image 172
Sheridan Avatar answered Apr 07 '23 19:04

Sheridan


To display a Drawing with an Image control,you can use a DrawingImage as the Image control's Source and the drawing you want to display.For more details visit here

   <DrawingImage x:Key='Skippy'>
        <DrawingImage.Drawing>
            <GeometryDrawing Brush="#FFF1A603" Geometry="F1M1737.61,7339.85C1720.49,7342.44 1709.83,7334.36 1709.83,7334.36  1701.44,7341.47 1682.84,7340.17 1682.84,7340.17 1682.66,7388.31 1709.83,7397.03 1709.83,7397.03 1741.17,7386.37 1737.61,7339.85 1737.61,7339.85 M1709.54,7386.88C1707.5,7386.88 1705.85,7385.23 1705.85,7383.18 1705.85,7381.14 1707.5,7379.49 1709.54,7379.49 1711.58,7379.49 1713.23,7381.14 1713.23,7383.18 1713.23,7385.23 1711.58,7386.88 1709.54,7386.88 M1712.37,7367.58C1712.37,7367.58 1712.28,7370.72 1710.94,7372.06 1710.94,7372.06 1709.33,7373.48 1707.54,7371.61 1707.54,7371.61 1707.09,7370.31 1706.47,7366.75L1705.48,7352.56 1705.48,7348.72C1705.48,7348.72 1705.59,7345.14 1709.61,7344.51 1709.61,7344.51 1713.36,7344.34 1713.53,7348.27 1713.53,7348.27 1713.98,7352.56 1712.37,7367.58"/>
        </DrawingImage.Drawing>
    </DrawingImage>

 <Image Source="{StaticResource Skippy}"  Height="30" Width="30"/>

and your path is must be implemented using expression blend thats why it is showing extra stuff like Path.RenderTransform.anyway output from our both code is same.

Output enter image description here

like image 36
Heena Avatar answered Apr 07 '23 21:04

Heena