Tech Off Post

Single Post Permalink

View Thread: Any xaml heads here?
  • User profile image
    Rob Relyea

    stevo_ said:
    Sven Groot said:
    Err, I can give you step by step if that helps..

    Start a new wpf app.. create a new user control

    Change the default xml namespace (xmlns) to the clr namespace of your project (ie, xmlns="clr-namespace:WpfApplication1")

    Remove the height and width properties, and delete the child grid..

    Change UserControl (root element) to TestObj (ensure you change the closing tag as well)..

    Now go into the code behind for that xaml and above the class add another:

    public class TestObj

    Change the code behind class to inherit from TestObj

    Everything should be happy (the wpf app won't run - but the designer and compilation will be happy)..

    Not add a property to TestObj.. sayyy:

    public bool IsXamlCool { get; set; }

    Go to the xaml and add IsXamlCool property add you'll get intellisense autocomplete, the designer will be happy and compiles etc..

    Then change the property to be


    As a child element.. you should get an error:

    "Unknown build error, 'Object reference not set to an instance of an object.'"

    I'm trying to work out if this is a bug with xaml, or I need to specify some type conversions to do even primative conversions like bools.
    This sounds like PropertyElements inside the XAML MarkupCompiler may have a problem with types from mscorlib which have type converters?  Our markupcompiler and the normal runtime parser sometime have bugs that cause them to not work consistently.  We now have a bug filed on this issue and will address this issue in the future.  For now, you can likely either:
    1) use an attribute to represent this value
    2) you may be able to add a property level type converter to point to BoolConverter, etc......However, this doesn't scale very well.  And you can only do it on properties that you define.

    The reason for this bug is probably the fact that types in MsCorLib can't be marked with TypeConverterAttributes since that is a System.dll thing.  We have a hard coded list in the XAML stack of the list of types from mscorlib that have type converters.

    In .NET 4, the WPF parser is being rearchitected to run on top of System.Xaml.dll that will make it so that if an attribute form works, so will the property element form.  The XamlXmlReader component will represent both of those situations we should have better behavior.

    The WPF forum and relevelant posts on blog are great places to ask XAML questions.

    Thanks, Rob Relyea
    Architect, XAML/WPF Teams