Error when setting header to a non string

Sep 11, 2010 at 7:28 PM

I love your TabControl. A great tool. :)

When I assigned a StackPanel to the header(With an image and a textblock) instead of a string I got an error in 2 cases:

When I look at the name list of the open tabs.

When I go to the thumbnail view the tabs title disappers.

Sep 21, 2010 at 7:13 PM


What your describing should be possible.  I have made a change to the sample project to illustrate how to do this.

Incidentally if you have a look at the CancelCloseEventWindow.xaml in the SampleProject I show an example of how to made the Header be more than just a string.  Basically the Header itself is still a string, the key is to set the HeaderTemplate to something with other graphical elements.

I hope that helps.



Sep 24, 2010 at 11:04 PM

Hi Johs,

Thanks for the sample.

What you did in the code fixed 1 thing and ruined something that worked. :)

What I did in my code was set through the code the header property.

FabTabItem item = new FabTabItem();

StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;

item.Header = sp;
If I do that there is a bug in when more than 1 tab is open in the tab selection and in the thumbnail view.
try it your self and take a look.
If you want a sample project get the code from this SVN:
The code is in MainWindow.xaml.cs
Thanks for replying, Randall
Sep 29, 2010 at 7:14 PM

Hi Randall,

Thanks for the additional info.  BTW, looks like a neat project you've got going there.

So basically you can follow your basic approach of doing everything in code if you want to.  But you've got to set (or bind the Header to the string you want to show up both in the header itself and in the ContentTabView ComboBox as well as for the title of the ImageButtons in the ContentTabView).  Then, so that you can completely customize the Visual Tree within the FabTabItem's Header, you can set a complex HeaderTemplate from code. Again, this would be much easier in XAML, the hierarchy of FrameworkElementFactories necessary to build up a DataTemplate from code is not fun to write.

If you pull down the latest FabTab changeset, have a look at the XAML and codebehind for TabItemsWindow.xaml.  When you click on the Add TabItem With Custom Header button off to the right, it calls the poorly-named Button_Click_7 event handler.  In that handler see how I manually build up the DataTemplate for the FabTabItem.HeaderTemplate, and then actually set the FabTabItem.Header itself to a string value.

If I don't have a place that FabTab can rely on to grab a string to show those other strings, then you end up seeing StackPanel's ToString() output in the dropdowns and over the ImageButtons on the ContentTabView.

Hope this helps. Good luck!