SVG Image elements and Asp.NET

2019-08-20 05:25发布

I am working with SVG and ASP.NET. I have some image elements defined as SVGs. Based on some manipulation, I want to change the path of SVG images from asp.net code behind.

I am new to SVG. Can some tell me how can I access SVG images in code behind and perform the desired operations. Any other guidance regarding SVG and asp.net would be highly appreciated.

This is my svg markup in web form:

<svg width="600" height="500">
    <rect x="10" y="10" height="250" width="500" style="fill:rgb(255, 255, 255);stroke-width:3;stroke:rgb(0,0,0)" />
    <image x="20" y="50" width="300" height="80"
           xlink:href="http://dely.com/Svg/images/Layout/top-bar-logo.png" />
    <image x="15" y="125" width="300" height="80"
           xlink:href="http://dely.com/Svg/images/Layers/left-bar.png" />
</svg>

标签: asp.net svg
1条回答
狗以群分
2楼-- · 2019-08-20 06:14

I don't see any problem by simply adding runat="server" and modifying URL from the code behind by using Attributes property:

<svg width="600"  height="500">
        <rect x="10" y="10" height="250" width="500" style="fill:rgb(255, 255, 255);stroke-width:3;stroke:rgb(0,0,0)" />

        <image runat="server" id="imgTest" x="20" y="50" width="300" height="80" 
            xlink:href="http://dely.com/Svg/images/Layout/top-bar-logo.png" />
        <image x="15" y="125" width="300" height="80"
            xlink:href="http://dely.com/Svg/images/Layers/left-bar.png" />

    </svg>

Code Behind (I placed new test URL):

imgTest.Attributes.Add("xlink:href", "http://icons.iconarchive.com/icons/aha-soft/free-3d-glossy-interface/64/accept-icon.png");
查看更多
登录 后发表回答