How to make a UI-MarkupExtension
Poor XAML parser is just really confused about all this...:O) Help it by eliminating ambiguity : instantiate MyList
explicitly in your XAML.
XAML:
<local:UserControlEx x:Class="WpfApp14.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp14"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="450">
<local:UserControlEx.MyList>
<local:ObjectCollection>
<local:CoolBlueRectangle/>
<local:CoolBlueRectangle/>
<local:CoolBlueRectangle/>
<local:CoolBlueRectangle/>
<local:CoolBlueRectangle/>
</local:ObjectCollection>
</local:UserControlEx.MyList>
<Grid>
<ItemsControl HorizontalAlignment="Left"
ItemsSource="{Binding MyList}"/>
</Grid>
</local:UserControlEx>
Where,
public class ObjectCollection : ObservableCollection<object>
{
}
BTW, the naming convention is that your markup class definition should use the Extension suffix.
public class CoolBlueRectangleExtension : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
}
}