views:

25

answers:

1

I have written a Well control, similar to the Visual Studio editor tabs so that a user can have multiple documents open and can see one or more at a time. It is derived from a UserControl and exposes an ObservableCollection of OpenDocuments that binds to the ViewModel. If I were to implement this as a simple TabControl, then this would be how it would look:

<TabControl
   Grid.Row="1"
   Grid.Column="1"
   ItemsSource="{Binding OpenDocuments}"
   SelectedItem="{Binding SelectedTab, Mode=TwoWay}">
   <TabControl.ItemTemplate>
     <DataTemplate>
       <TextBlock
         Text="{Binding Name}" />
     </DataTemplate>
   </TabControl.ItemTemplate>
   <TabControl.ContentTemplate>
     <DataTemplate>
       <vw:DocumentView />
     </DataTemplate>
   </TabControl.ContentTemplate>
 </TabControl>

This gives me Name in the tabitem header and the DocumentView (another user control in the Content area).

My control has a ContentTemplate but it is of course representing the whole of the control so all I get to see is the DocumentView. My control doesn't have an ItemTemplate.

How do I expose an ItemTemplate and ContentTemplate?

Andrew

EDIT -------------------------------------------------------------------------

Thanks for the replies. It looks like this: Well

A user can have one or more document wells holding one or more tabs. All the consumer has access to is the list of visible tabs and the currently selected tabitem.

Notice that the tabs are all empty! I don't understand how to specify the ContentTemplate for the <vw:DocumentView> in the same way as the TabControl example above.

Andrew

A: 

I am a little confused on exactly what your control looks like but here is what I think you are after.

If your control can inherit from ItemsControl you will get the ItemTemplate property already defined for you. All you have to do in your control template is to Template bind the ItemsControl property to the correct place in the template.

The same applies for the ContentTemplate. If you have the a ContentTemplate property already defined for you control you just need to Template Bind it to the correct place in the control.

It would look something like this

Control Consumer

<MyControlNamespace:MyControl ContentTemplate="{StaticResource MyContentTemplate}" ItemTemplate="{StaticResource MyItemTemplate}" />

Implementation of "MyControl" from above (totally pseudo code)

<MyControl>
  <ItemsPresenter ItemTemplate="{TemplateBinding ItemTemplate}" />
  <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" />
</MyControl>

Again, my example doesn't fully make sense but I am not sure what your control looks like and not entirely sure what you are asking, but hopefully this helps.

Foovanadil