2
votes

I am using VS2010's WPF Ribbon Application. Each RibbonGroup has a Header. Even If I leave the Header empty, the Ribbon will still reserve an empty space for the Header. How can I programmatically hide the header?

For instance, I have following Xaml:

<ribbon:RibbonTab x:Name="HelpTab"
                    Header="Help" FontSize="10">
    <ribbon:RibbonGroup x:Name="HelpGroup"
                        Header="Help Group" FontFamily="Verdana" FontWeight="Bold">
             <!-- ..... -->
        </ribbon:RibbonButton>
    </ribbon:RibbonGroup>
</ribbon:RibbonTab>
</ribbon:Ribbon>

I want to programmatically hide the part (header text and height space) marked by red rectangle.

enter image description here

I'm looking for a C# code behind solution where I could hide the text and the space (height) the header takes up all together, something such as below:

// of course, this doesn't work    
HelpTab.HeaderStyle.Visibility = Visibility.Hide
2
I am looking for solution other than a hack - e.g. using margin to hide it..KMC

2 Answers

0
votes

You can do it via the VisualTreeHelper. Just go set the row MinHeight to 0 :

private void RibbonLoaded(object sender, RoutedEventArgs e)
{
  DependencyObject groupBorder = VisualTreeHelper.GetChild(Foobar, 0);
  Grid groupMainGrid = VisualTreeHelper.GetChild(groupBorder , 0) as Grid;
  if (groupMainGrid != null)
  {
    groupMainGrid.RowDefinitions[2].MinHeight = 0;
  }
} 

This is assuming that you didn't set the Header property. The height of the row is set by default to Auto. So if you set the Header property, you might as well set the Height to 0 :

groupMainGrid.RowDefinitions[2].Height = 0;
0
votes

You can always create stack panel instead of ribbon group.