Hide SVG element from C#

北城余情 提交于 2020-01-25 04:43:06

问题


I have a svg which contains two groups.

<svg viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
  <g id="gr1" fill="white" stroke="green" stroke-width="5">
    <circle cx="40" cy="40" r="25" />
    <circle cx="60" cy="60" r="25" />
  </g>
  <g id="gr2" fill="white" stroke="green" stroke-width="5">
    <circle cx="90" cy="60" r="25" />
    <circle cx="96" cy="40" r="25" />
  </g>
</svg>

Is there a way, using C# or javascript (preferably C#), to hide the group gr2 at some event (button click, x value>y value, etc)? I know that visibility="hidden" does what I want, but I don't know how to call it for a group of my SVG.


回答1:


Try this:

<svg  viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
  <g id="gr1" fill="white" stroke="green" stroke-width="5">
    <circle cx="40" cy="40" r="25" />
    <circle cx="60" cy="60" r="25" />
  </g>
  <g runat="server"  id="gr2" fill="white" stroke="green" stroke-width="5">
    <circle cx="90" cy="60" r="25" />
    <circle cx="96" cy="40" r="25" />
  </g>
</svg>

and in c#

{
    gr2.Visible = false;
}


来源:https://stackoverflow.com/questions/59262595/hide-svg-element-from-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!