views:

96

answers:

1

Hello,

for reasons based on storabiligty I have the following objects in a XAML graph:

  • A WorkArea,
  • Containing WorkSheets,
  • Containing WorkItems

WorkArea, workSheets are ItemsControl instances.

To start: The reason that I am not using standard elements here is that mine are going to get loaded / saved - they represent a business contect (actually the work area of a trading application), and I want those to have as few "surplus" elements as I can. I especially do not want to be tied into user level controls that are from a third party and regularly changing dll names (during upgrades - the major version is encoded there) and I am not sure I will not replace them at all, so I rather go with my own "slim" objects.

The WorkArea corresponds to a window (actually there is a WorkAreaWindow that will take the WorkArea as ContentItem.

The WorkSheets are supposed to work like a TabControl - you can switch between them.

How do I do that? ;)

I get the impression that with the templating mechanisms I could possibly "visuall wrap" the WorkSheets as pages in a TabControl, but I am pretty much totally lost on the how. Anyone can enlighten me?

Here is how far I got:

My Herarchy is WorkArea -> WorkSheet(s) -> WorkItem(s)

WorkArea should be presented as a TabControl, with one tab per WorkSheet.

WorkArea:

        <local:WorkArea x:Name="WorkArea">
            <local:WorkArea.Template>
                <ControlTemplate>
                    <TabControl>
                        <ItemsPresenter />
                    </TabControl>
                </ControlTemplate>
            </local:WorkArea.Template>

            <local:WorkArea.ItemTemplate>
                <DataTemplate>
                    <TabItem Header="{Binding Path=Title}">
                        <ContentPresenter />
                    </TabItem>
                </DataTemplate>
            </local:WorkArea.ItemTemplate>
            <local:WorkSheet Title="Markets">
                <local:WorkTile local:WorkSheet.Row="2" local:WorkSheet.Column="3">
                    test-11

What I can see now is a TabControl, with one Tab. No text, all content in the one tab. Anyone an idea how to split this further?

+3  A: 

You should carefully read Josh Smith's introduction to MVVM here and look at the demo application source code. The demo application is almost exactly what you are asking for. It generates a tabbed interface dynamically based on custom classes for "contacts" data using data templates, observable collection binding and tabcontrol/tabitem. Some of the MVVM and commanding stuff might not be your thing, but a portion of the code does what you are looking for. The XAML has no code behind at all. You would simply set that data context of your window to your work area class instance that would have an observable collection of worksheets which in turn have an observable collection of workItems and item/data templates will do everything.

astonish