The title basically points it out. I've read other blogs and posts related to the same issue, but none of the provided solutions did work for me.
Here's a simplification of my code:
<!-- CustomItemsControl.xaml -->
<ItemsControl x:Class="myNamespace.CustomItemsControl"
xmlns:local="clr-namespace:myNamespace">
<ItemsControl.Resources>
<Style TargetType="{x:Type local:CustomItemsControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomItemsControl}">
<Grid x:Name="MyItemsHost" Background="{TemplateBinding Background}" IsItemsHost="True"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Resources>
</ItemsControl>
// CustomItemsControl.xaml.cs
namespace myNamespace
{
public partial class CustomItemsControl : ItemsControl
{
public CustomItemsControl()
{
this.DefaultStyleKey = typeof(CustomItemsControl);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var MyItemsHost = (Grid)base.GetTemplateChild("MyItemsHost");
}
}
}
What I'm doing wrong?