?
Solved

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

Posted on 2011-02-21
3
Medium Priority
?
928 Views
Last Modified: 2013-11-12
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?
0
Comment
Question by:cbordeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:saragani
ID: 35066180
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.
0
 
LVL 11

Accepted Solution

by:
saragani earned 2000 total points
ID: 35066735
Anyhow, I think I have a solution for your problem, using Relative Source:

<Window x:Class="MyWizard.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyWizard"
        Title="MainWindow" Height="350" Width="525">
    
    <Window.Resources>
        <ControlTemplate TargetType="{x:Type local:Wizard}" x:Key="myWizard">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <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"/>
            </Grid>
            
        </ControlTemplate>
    </Window.Resources>
    
    <Grid>
        <local:Wizard Template="{StaticResource myWizard}" SelectedIndex="0">
            <local:WizardPage>
                <local:WizardPage.Content>
                    <Button>Hello World</Button>
                </local:WizardPage.Content>
                <local:WizardPage.TopLeftContent>
                    <Button>My first name is Itai</Button>
                </local:WizardPage.TopLeftContent>
                <local:WizardPage.TopRightContent>
                    <Button>My last name is Sargani</Button>
                </local:WizardPage.TopRightContent>
            </local:WizardPage>
            <local:WizardPage>
                <Button>Hello World 2</Button>
            </local:WizardPage>
            <local:WizardPage>
                <Button>Hello World 3</Button>
            </local:WizardPage>
        </local:Wizard>
    </Grid>
</Window>

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
0
 

Author Comment

by:cbordeman
ID: 35069372
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question