locked
WPF SVG binding in code behind RRS feed

  • Question

  • Is there any plan in near future to provide below functionality in visual studio WPF.
    Can we directly bind the .SVG file in the WPF code behind, as we can currently bind image in grid and image controls.


    Pankaj Deharia

    • Moved by Amanda Zhu Tuesday, November 18, 2014 6:29 AM
    Monday, November 17, 2014 11:01 AM

Answers

  • Hi,

    Thanks for posting on MSDN Forum.

    >> Is there any plan in near future to provide below functionality in visual studio WPF?<<

    For this issue, you can flow WPF Team blog, please check here: http://blogs.msdn.com/b/dotnet/archive/2014/11/12/the-roadmap-for-wpf.aspx

    Also, if this feature is important to you. You can submit a user voice here:

    http://dotnet.uservoice.com/forums/40583-wpf-feature-suggestions

    Thanks for your understanding!

    >> Can we directly bind the .SVG file in the WPF code behind, as we can currently bind image in grid and image controls?<<

    I am afraid that we cannot do that now. For how to use SVG file in XAML, please check:

    http://stackoverflow.com/questions/3526366/wpf-what-is-the-correct-way-of-using-svg-files-as-icons-in-wpf

    Best Regards,

    Jimmy Yang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 18, 2014 6:41 AM
  • Although you can't bind svg, it's possible to convert them to geometries.

    I use inkscape for this:

    https://inkscape.org/en/

    You can use the resulting string as a geometry and bind a path to it.

                <Button  Command="{Binding ShowLayout2}"
                         Background="{StaticResource ResourceKey=LightBrightGradientBrush}">
                    <Grid>
                        <Path Data="{StaticResource eMailIcon}"
                                                  Stretch="Uniform" Fill="{StaticResource MidDullBrush}" Width="20" Height="20" RenderTransformOrigin="0.5,0.5">
                        </Path>
                    </Grid>
                </Button>

    Resource dictionary:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      
                        >
        
        <Geometry x:Key="eMailIcon">M0,8.5909986L28.326799,29.197784C32.25,32.373585,35.237099,29.385284,35.237099,29.385284L64,8.5909986 64,47.064999 0,47.064999z M0,0L63.875,0 63.875,3.7343616 32.872349,26.146971C32.872349,26.146971,31.87495,27.018066,31.127552,26.271971L0,3.4856424z</Geometry>
    

    Tuesday, November 18, 2014 8:33 AM

All replies

  • Hi Pankaj,

    Because your question is about WPF feature, I moved this thread to Windows Presentation Foundation (WPF) forum. WPF will provide you better answer.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 18, 2014 6:30 AM
  • Hi,

    Thanks for posting on MSDN Forum.

    >> Is there any plan in near future to provide below functionality in visual studio WPF?<<

    For this issue, you can flow WPF Team blog, please check here: http://blogs.msdn.com/b/dotnet/archive/2014/11/12/the-roadmap-for-wpf.aspx

    Also, if this feature is important to you. You can submit a user voice here:

    http://dotnet.uservoice.com/forums/40583-wpf-feature-suggestions

    Thanks for your understanding!

    >> Can we directly bind the .SVG file in the WPF code behind, as we can currently bind image in grid and image controls?<<

    I am afraid that we cannot do that now. For how to use SVG file in XAML, please check:

    http://stackoverflow.com/questions/3526366/wpf-what-is-the-correct-way-of-using-svg-files-as-icons-in-wpf

    Best Regards,

    Jimmy Yang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 18, 2014 6:41 AM
  • Although you can't bind svg, it's possible to convert them to geometries.

    I use inkscape for this:

    https://inkscape.org/en/

    You can use the resulting string as a geometry and bind a path to it.

                <Button  Command="{Binding ShowLayout2}"
                         Background="{StaticResource ResourceKey=LightBrightGradientBrush}">
                    <Grid>
                        <Path Data="{StaticResource eMailIcon}"
                                                  Stretch="Uniform" Fill="{StaticResource MidDullBrush}" Width="20" Height="20" RenderTransformOrigin="0.5,0.5">
                        </Path>
                    </Grid>
                </Button>

    Resource dictionary:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      
                        >
        
        <Geometry x:Key="eMailIcon">M0,8.5909986L28.326799,29.197784C32.25,32.373585,35.237099,29.385284,35.237099,29.385284L64,8.5909986 64,47.064999 0,47.064999z M0,0L63.875,0 63.875,3.7343616 32.872349,26.146971C32.872349,26.146971,31.87495,27.018066,31.127552,26.271971L0,3.4856424z</Geometry>
    

    Tuesday, November 18, 2014 8:33 AM