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 638307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:43:07+00:00 2026-05-13T20:43:07+00:00

I have some string representations of Xaml objects, and I want to build the

  • 0

I have some string representations of Xaml objects, and I want to build the controls. I’m using the XamlReader.Parse function to do this. For a simple control such as Button that has a default constructor not taking any parameters this works fine:

var buttonStr = "<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">Text</Button>";
var button = (Button)XamlReader.Parse(buttonStr); 

However, when I try to do this to e.g. a Stroke control it fails. First trying a simple empty Stroke:

var strokeStr = "<Stroke xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"></Stroke>";
var stroke = (Stroke)XamlReader.Parse(strokeStr);

This gives the error:

Cannot create object of type ‘System.Windows.Ink.Stroke’. CreateInstance failed, which can be caused by not having a public default constructor for ‘System.Windows.Ink.Stroke’.

In the definition of Stroke I see that it needs at least a StylusPointsCollection to be constructed. I assume this is what the error is telling me, though was kinda assuming this would be handled by the XamlReader. Trying to transform a Xaml of Stroke with StylusPoints in it gives the same error:

var strokeStr = 
    "<Stroke xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" + 
        "<Stroke.StylusPoints>" + 
            "<StylusPoint X=\"100\" Y=\"100\" />" +
            "<StylusPoint X=\"200\" Y=\"200\" />" + 
        "</Stroke.StylusPoints>" + 
    "</Stroke>";
var stroke = (Stroke) XamlReader.Parse(strokeStr);

What am I doing wrong? How do I tell the XamlReader how to create the Stroke correctly?

  • 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-13T20:43:07+00:00Added an answer on May 13, 2026 at 8:43 pm

    It’s a “feature” of the XAML language, it is declarative and doesn’t know anything about constructors.

    People use ObjectDataProvider in XAML to “translate” and wrap instances of classes that do not have a parameterless constructor (it’s also useful for data binding).

    In your case the XAML should look approximately like this:

    <ObjectDataProvider ObjectType="Stroke">
        <ObjectDataProvider.ConstructorParameters>
            <StylusPointsCollection>
                <StylusPoint X="100" Y="100"/>
                <StylusPoint X="200" Y="200"/>
            </StylusPointsCollection>
        </ObjectDataProvider.ConstructorParameters>
    </ObjectDataProvider>
    

    And the code should be:

    var stroke = (Stroke) ((ObjectDataProvider)XamlReader.Parse(xamlStr)).Data;
    

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some string like this: 04:51 05:09 05:29_ 05:49 06:09 06:29 06:49_ 07:09
HI, I have some string from XML file, and I I want to replace
I have some random string, let's say : s = This string has some
I have some problem to get the utf-8 string from PHP using jQuery $.load()
I have some java.sql.Time objects as follows: String s1 = 12:00:04; String s2 =
I have some html extracted to a string var, and want to then use
I have some String[] arrays, for example: ['a1', 'a2'] ['b1', 'b2', 'b3', 'b4'] ['c1']
I have some code in a python string that contains extraneous empty lines. I
I have some code static void Main(string[] args) { int j = 0; for
I have some text that is being read in from the database. This text

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.