Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Ribbon - hiding tab header (single tab application)

Tags:

wpf

ribbon

I am new to WPF and am trying to use the Ribbon control.

I have a single tab in the application, and wish to hide the header but still show the tab itself.

I have been experimenting with various properties and styles, but I have only been able to hide the entire tab.

I've tried: ribbontab visibility, ribbontab.header visibility, setting hidden in TabHeaderItemCollection, applying style xaml to ribbontabheader element in ribbontab, experimenting with tabheadertemplate property, and generally sifting through the api looking for anything that may be relevant.

Google only turns up how to hide the whole tab.

Any other ideas?

like image 358
SeeMoreGain Avatar asked May 05 '14 04:05

SeeMoreGain


1 Answers

I managed to hide both the tab headers and the application menu by shifting the control 47 pixels upwards...

<r:Ribbon Margin="0,-47,0,0" DockPanel.Dock="Top" x:Name="ribbon">

Note: you can hide just the application menu and not the tabs by doing this...

<r:Ribbon DockPanel.Dock="Top" x:Name="ribbon">             
    <r:Ribbon.ApplicationMenu>
        <r:RibbonApplicationMenu Visibility="Collapsed" />
    </r:Ribbon.ApplicationMenu>

Hiding just the tab headers, I can't quite do. I did get pretty close by overriding the ribbon class as follows...

class RibbonNoTab : Ribbon
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        var ctrl = this.GetDescendants<Grid>().FirstOrDefault();
        if (ctrl != null)
        {
            ctrl.RowDefinitions[1].Height = new GridLength(0, System.Windows.GridUnitType.Pixel);
        }
    }
}

The GetDescendants extension method just searches the visual tree for something of a specified type. It was taken from here: http://blog.falafel.com/finding-controls-by-type-in-silverlight-and-wpf/

The only issue with the above method was that there looks like a 1 pixel high bar remaining. You have to look pretty closely to see it!

like image 109
flobadob Avatar answered Sep 30 '22 15:09

flobadob