tags:

views:

39

answers:

1

Given a simple C# class definition like:

    [System.Windows.Markup.ContentProperty("PropertyOne")]
    public class SimpleBase
    {
        public string PropertyOne { get; set; }
        public string PropertyTwo { get; set; }
    }

why is it not possible to omit the sys:string tags around the word Test in the xaml below.

<custom:SimpleBase x:Class="TestType"
                   xmlns:custom="clr-namespace:ConsoleApplication1;assembly="
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <sys:String>Test</sys:String>
</custom:SimpleBase>

Somehow the compiler correctly converts text to string for the type String, why doesn't it work for my custom type?

The context can be found on my blog: http://www.deconflations.com/?tag=xaml

A: 

So, after much digging I unearthed the problem. In order to be able to support custom content the base class MUST be declared in a different assembly.

Talk about obscure. Still, move the definition of SimpleBase to a new assembly and update the definition of xmlns:custom to match and Bingo, no more errors with just using direct string content.

Thanks for reading.

Duncan