I have an control that is subclassed from ItemsControl, called WorkSheet.
public sealed class WorkSheet : ItemsControl {
It's elements are forced to be WorkTiles.
/// <inheritdoc />
protected override bool IsItemItsOwnContainerOverride(object item) {
return (item is WorkTile);
}
/// <inheritdoc />
protected override DependencyObject GetContainerForItemOverride() {
return new WorkTile();
}
So far - so good. I want the WorkSheet to use a Canvas for presenting the WorkItems, position being determined by overriing ArrangeOverride, which is called and positions properly determined. The exact psosition is being determined in overrides. I am pretty lost in the styling, though. I simply can not get the items to appear. In The Generic.xaml, I have defined the styles. They work, but not as they should:
<Style TargetType="{x:Type local:WorkSheet}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border>
<ItemsPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<ContentPresenter />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Here,pretty much, in the presentation tree, the ItemsPresenter is the lowest element. The subelements iof ItemsPresenter never appear. I also tried putting a Canvas into the ControlTemplate with IsItemsHost="true" - again, no items. Anyone any idea what I am doing wrong here?
Again, as explanation - I put a breakpoint into a button handler on the form and use the Visualizer to see the visual tree. The hierarchy I get is:
WorkSheet -> Border -> ItemsPresenter ... and nothing below.
Obviously this means the ControlTemplate is used, but the ItemsPanel is never invoked.