locked
XAMLParseException error RRS feed

  • Question

  • Hi,

    I have an UserControl that has user code (C#) that gives the following exception;

    Cannot create object of type 'VeloDrome.BlueCircle'. CreateInstance failed, which can be caused by not having a public default constructor for 'VeloDrome.BlueCircle'.  Error at object 'LayoutRoot' in markup file 'MainWindow.xaml' Line 17 Position 4.

    It only give me this error when I try to create an overloaded constructor.






    <

     

    UserControl

    xmlns

     

    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns

     

    :x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns

     

    :d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns

     

    :mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc

     

    :Ignorable="d"

    x

     

    :Class="VeloDrome.BlueCircle"

    x

     

    :Name="UserControl"

    d

     

    :DesignWidth="26" d:DesignHeight="26">

     

     

    <Canvas x:Name="LayoutRoot">

     

     

    <Ellipse x:Name="BlueCircle_Copy" Stroke="Black" Width="26" Height="26">

     

     

    <Ellipse.Fill>

     

     

    <RadialGradientBrush>

     

     

    <GradientStop Color="#FF241C6E" Offset="1"/>

     

     

    <GradientStop Color="#FF4DECD4"/>

     

     

    </RadialGradientBrush>

     

     

    </Ellipse.Fill>

     

     

    </Ellipse>

     

     

    </Canvas>

    </

     

    UserControl>


    -------------

    Sunday, March 7, 2010 7:52 PM

Answers

  • As you have discovered, your usercoontrol has to have a parameterless constructor to work properly.  If you are creating the objects in code, you can use the initializer syntax (var o = new Object() { Prop1 = value, Prop2 = value};)

    Monday, March 8, 2010 3:25 PM
    Moderator