0

div で構成される UserControl を作成したいと考えています。div の内側には、SVG でレンダリングされた多数のボックスがあります。データから決定されるボックスの数とそれらの相対位置。

データは、クラス Box のリストの形式になります。Box は次のとおりです。

 public class SVGBox
 {
    public int x { get; set; }  // x coordinate of a corner
    public int y { get; set; }  // x coordinate of same corner
    public int l { get; set; }  // length
    public int h { get; set; }  // height
    public string Color { get; set; }
    public string text { get; set; }
    public string uniqueKey { get; set; }

    public SVGBox (int X, int Y, int H, int W, string Text, string Key )
    {
        x = X;
        y = Y;
        h = H;
        w = W;
        text = Text;
        uniqueKey = Key;
    }
 }  

C# から SVG をレンダリングするために 'Net で見つけた例がありますが、DOCTYPE で特定の参照を使用して HTML ページ全体を書き出す必要があります。ユーザーコントロール内でこれを行うにはどうすればよいですか?

4

1 に答える 1

0

わかりました、いったん正しいスタートを切ったので、それほど悪くはありません。

ascx では、単に asp:Literal を追加しました。コードビハインドは次のとおりです。

public partial class Controls_SVGTest : System.Web.UI.UserControl
{
    public int Height { get; set; }
    public int Width { get; set; }
    public List<SVGBox> data { get; set; }

    const string HeaderText = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <svg xmlns=\"http://www.w3.org/2000/svg\" " +
                                "xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"{0}\" width=\"{1}\" >";

    const string BoxSVG = "<rect x=\"{0}\" y=\"{1}\" height=\"{2}\" width=\"{3}\" rx=\"2\" fill=\"{4}\" stroke=\"#707070\" />";
    const string Footer = "</svg>";


    protected void Page_Load(object sender, EventArgs e)
    {
        LoadSVG();
    }

    public void LoadSVG()
    {
        Literal1.Text = String.Format(HeaderText, Height.ToString(), Width.ToString());
        foreach (SVGBox s in data)
        {
            Literal1.Text += String.Format(BoxSVG, s.x, s.y, s.h, s.w, s.Color);
        }
        Literal1.Text += Footer;
    }

}
于 2013-01-18T22:44:25.083 に答える