views:

55

answers:

3

I have a bunch of different objects that are commonly edited in the same TabControl using different DataTemplates, but I want each DataTemplate to have a common look and feel with Ok and Cancel buttons at the bottom right of each tab that will close the tab or save the content and then close the currently selected tab. What's the best way to place buttons on each tab ? Is there a way to do it without copying and pasting the buttons and stack panel across all of my data templates ?

A: 

You could make a base view class that held those buttons. Views that needed the buttons would inherit them and common functionality.

Scott J
+1  A: 

Sure, you can create your own OkCancelSaveControl. In WPF, creating a "user control" is much easier than it sounds. Here is a tutorial. In a nutshell, you

  1. create a new user control,
  2. create properties in the user control that give the your control the information it needs to perform its duties (e.g. the tab that it's supposed to close or the data object that it's supposed to save),
  3. if necessary, create events that the user control raises (OkClick), in case some tab requires special treatment.
Heinzi
That was my first thought, as well. But then I thought you'd need to hook into the button's event/commands everywhere you used it. Implemented as a base class, common functionality could be inherited.
Scott J
A: 

I would make a custom control, lets call it MyCoolTabItem, that inherits from the TabItem class, and just throw your buttons into the control. Then just add a MyCoolTabItem instead of a TabItem to all of your TabControls and it will have all of your buttons on it.

smoore