[英]Programmatically hide WPF Ribbon Header
I am using VS2010's WPF Ribbon Application.我正在使用 VS2010 的 WPF 功能区应用程序。 Each RibbonGroup has a Header.
每个 RibbonGroup 都有一个 Header。 Even If I leave the Header empty, the Ribbon will still reserve an empty space for the Header.
即使我将 Header 留空,功能区仍会为 Header 保留一个空白空间。 How can I programmatically hide the header?
如何以编程方式隐藏 header?
For instance, I have following Xaml:例如,我有以下 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.我想以编程方式隐藏由红色矩形标记的部分(标题文本和高度空间)。
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:我正在寻找解决方案后面的 C# 代码,我可以在其中隐藏文本和 header 占用的空间(高度),如下所示:
// of course, this doesn't work
HelpTab.HeaderStyle.Visibility = Visibility.Hide
You can do it via the VisualTreeHelper
.您可以通过
VisualTreeHelper
来完成。 Just go set the row MinHeight
to 0:只需 go 将行
MinHeight
设置为 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.这是假设您没有设置
Header
属性。 The height of the row is set by default to Auto
.行的高度默认设置为
Auto
。 So if you set the Header
property, you might as well set the Height
to 0:所以如果你设置了
Header
属性,你不妨把Height
设置为 0:
groupMainGrid.RowDefinitions[2].Height = 0;
You can always create stack panel instead of ribbon group.您始终可以创建堆栈面板而不是功能区组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.