Make TabControl show contents based on multiple (derived) TabItem Dependency Properties

I'm deriving TabControl to make a control called Wizard.  Wizard can only contain instances of WizardPage (derived from TabItem).

WizardPage contains, along with the existing Content, a "TopLeftContent" and "TopRightContent" which the user defines in XAML.  My Wizard needs to show all three of these somehow in the display area.

The Wizard's existing template uses a ContentPresenter to display ContentSource="SelectedContent", which automagically somehow returns SelectedItem.Content (the currently selected TabItem's Content property).  My problem is that I have no idea how to make a ContentPresenter display ContentSource="SelectedItem.TopLeftContent".  This syntax isn't supported apparently.

I've looked quite extensively, but I can't seem to figure out how to do this w/o exposing another DP that the user will foolishly want to bind to.  I need this to work against the SelectedItem.

Is there a way?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

saraganiConnect With a Mentor Commented:
Anyhow, I think I have a solution for your problem, using Relative Source:

<Window x:Class="MyWizard.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <ControlTemplate TargetType="{x:Type local:Wizard}" x:Key="myWizard">
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>

                <ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Wizard},AncestorLevel=1}, Path=SelectedItem.TopLeftContent}" Grid.Row="0" Grid.Column="0"/>
                <ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Wizard},AncestorLevel=1}, Path=SelectedItem.TopRightContent}" Grid.Row="0" Grid.Column="1"/>
                <ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Wizard},AncestorLevel=1}, Path=SelectedItem.Content}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/>
        <local:Wizard Template="{StaticResource myWizard}" SelectedIndex="0">
                    <Button>Hello World</Button>
                    <Button>My first name is Itai</Button>
                    <Button>My last name is Sargani</Button>
                <Button>Hello World 2</Button>
                <Button>Hello World 3</Button>

Open in new window

In my opinion, instead of templating the wizard to show the content of each page, I would have created a template for the pages.

I hope it helps you
First, I would suggest using MVVM for what you are doing. Your whole code seem to be based on XAML, which makes doesn't make it dynamic.

Can you post your code? It would make it easier to understand what you are doing.
cbordemanAuthor Commented:
Thanks, saragani, RelativeSource works great.  Coming from Silverlight, that solution didn't occur to me.

However, I do need to keep the template on the Wizard because that's the way TabControl (from which I derived) works.  It doesn't actually display any TabItems; it just displays their Content.  The advantage of using TabControl is it provides a useful set of tabs for design time navigation, which I hide at runtime.

I can't use MVVM directly here simply because this is a control to be used in many places and I can't rely on being bound to any known base viewmodel type.
All Courses

From novice to tech pro — start learning today.