Reputation: 505
I want to create a custom "Wizard"-Control.
So I derived a "Wizard" from Selector and created a "WizardPage" derived from HeaderedContentControl. Everything works fine, when I add the "WizardPages" directly to the "Wizard"'s Content itself.
In Code: This works
<ctrl:Wizard>
<ctrl:WizardPage Header="Page 1" Content="Some Stuff" />
</ctrl:Wizard>
Then I thought: Hey, it would be great if you can put random stuff in the Wizard's Content and if needed he creates a wrapper around it, just like the ListBox with the ListBoxItems (I definately need a wrapper, because the WizardPage needs the properties "CanLeavePage" and "AlreadyVisited").
In Code: I want that this works (Groups is a list of whatever, which I can template somewhere to WizardPage)
<ctrl:Wizard ItemsSource="{Binding Groups}" />
So I tried:
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is WizardPage;
}
protected override DependencyObject GetContainerForItemOverride()
{
return new WizardPage();
}
When I set breakpoints on those two methods I can see that IsItemItsOwnContainer gets called, but GetContainerForItemOverride never gets called.
What am I missing here?
The concept looks like this:
Upvotes: 0
Views: 1394
Reputation: 11051
Ok after checking your code its clear why it doesn't work. Your Wizard class is a Selector so its an ItemsControl, but in your wizard control template you don't use any of ItemsControl stuff, inside the Template you use a ListBox, which is an ItemsControl itself, and there you bind The Wizards ItemsSource to the ItemsSource of the listbox. So in the ListBox is now the ItemContainerGenerator called to generate ListBoxItems, because effectively the list box is doing all the work, while the wizard does nothing except rerouting the ItemsSource property.
You need to greatly modify your Wizard Template to make it work. Btw. you can easily derive the Wizard class from the ListBox.
Upvotes: 1