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:Ribbon开发者_如何学编程Tab>
</ribbon:Ribbon>
I want to programmatically hide the part (header text and height space) marked by red rectangle.
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
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;
You can always create stack panel instead of ribbon group.
精彩评论