Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 391227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:02:28+00:00 2026-05-12T16:02:28+00:00

I have a silverlight app that allows the user to draw on it and

  • 0

I have a silverlight app that allows the user to draw on it and save the drawing.

The strokecollection in the canvas is converted to xml attributes and stored in the database.

the only problem i have now is converting the xml back into a stroke collection.

my strokes are stored as such:

<Strokes>    
  <Stroke>    
    <Color A="255" R="0" G="0" B="0" />      
    <OutlineColor A="0" R="0" G="0" B="0" />      
  <Points>
    <Point X="60" Y="57" PressureFactor="0.5" />        
    <Point X="332" Y="52" PressureFactor="0.5" />      
  </Points>      
  <Width>3</Width>      
  <Height>3</Height>    
  </Stroke>  
</Strokes>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:02:28+00:00Added an answer on May 12, 2026 at 4:02 pm

    Here is your code heavily factored:-

    private StrokeCollection CreateStrokeCollection(string XMLStrokes)
    {
      XElement xmlElem;
      try
      {
        return CreateStrokeCollect(XElement.Parse(XMLStrokes).Root);
      }
      catch (XmlException ex)
      {
        return new StrokeCollection();
      }
    }
    
    private StrokeCollection CreateStrokeCollection(XElement elem)
    {  
      StrokeCollection result= new StrokeCollection();
      foreach (XElement elem in xmlElement.Elements("Stroke"))
      {
         result.Add(CreateStroke(elem));
      }
      return result;
    }
    
    
    private Stroke CreateStroke(XElement elem)
    {
      var result = new Stroke();
      result.DrawingAttributes = CreateAttributes(elem);
      result.StylusPoints.Add(CreatePointCollection(elem.Element("Points"));
      return result;
    }
    
    private StylusPointCollection CreatePointCollection(XElement elem)
    {
      var result = new StylusPointCollection();
      foreach (XElment pointElem in elem.Elements("Point"))
      {
        result.Add(CreateStylusPoint(pointElem));
      }
      return result;
    }
    
    private StylusPoint CreateStylusPoint(XElement elem)
    {
        double x = Convert.ToDouble(point.Attribute("X").Value);
        double y = Convert.ToDouble(point.Attribute("Y").Value);
        return new StylusPoint(x, y);
    }
    
    private DrawingAttributes CreateAttributes(XElement elem)
    {
       var result = new DrawingAttributes();
       result.Color = CreateColor(elem.Element("Color"));
       result.OutlineColor = CreateColor(elem.Element("OutlineColor"));
       result.Width = Convert.ToInt32(elem.Element("Width").Value);
       result.Height = Convert.ToInt32(elem.Element("Height").Value);
       return result ;
    }
    
    private Color CreateColor(XElement elem)
    {
      byte colorA = Convert.ToByte(color.Attribute("A").Value);
      byte colorR = Convert.ToByte(color.Attribute("R").Value);
      byte colorG = Convert.ToByte(color.Attribute("G").Value);
      byte colorB = Convert.ToByte(color.Attribute("B").Value);
    
      return Color.FromArgb(colorA, colorR, colorG, colorB);       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.