0

当我在 WPF 中添加功能区时,我得到了一个完整的功能区控件。如何隐藏除应用程序菜单按钮之外的所有内容?我可以做一些变通方法,但有什么标准方法可以隐藏其他面板吗?

在此处输入图像描述

我懒得为此设计自己的控件

4

1 回答 1

0

Loaded您可以在事件中清除项目并将功能区高度属性设置为 45 。

   <ribbon:Ribbon x:Name="Ribbon" Loaded="Ribbon_Loaded">
        <ribbon:Ribbon.ApplicationMenu>
            <ribbon:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
                <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                  x:Name="MenuItem1"
                                                  ImageSource="Images\LargeIcon.png"/>
            </ribbon:RibbonApplicationMenu>
        </ribbon:Ribbon.ApplicationMenu>
        <ribbon:RibbonTab x:Name="HomeTab" 
                          Header="Home">
            <ribbon:RibbonGroup x:Name="Group1" 
                                Header="Group1">
                <ribbon:RibbonButton x:Name="Button1"
                                     LargeImageSource="Images\LargeIcon.png"
                                     Label="Button1" />

                <ribbon:RibbonButton x:Name="Button2"
                                     SmallImageSource="Images\SmallIcon.png"
                                     Label="Button2" />
                <ribbon:RibbonButton x:Name="Button3"
                                     SmallImageSource="Images\SmallIcon.png"
                                     Label="Button3" />
                <ribbon:RibbonButton x:Name="Button4"
                                     SmallImageSource="Images\SmallIcon.png"
                                     Label="Button4" />                    
            </ribbon:RibbonGroup>                
        </ribbon:RibbonTab>
    </ribbon:Ribbon> 

代码隐藏:

private void Ribbon_Loaded(object sender, RoutedEventArgs e)
{
    Ribbon menu = sender as Ribbon;
    menu.Height = 45;
    menu.Items.Clear();
}

您可以使用它单独的外部功能区控件,但在这种情况下,您将在下拉菜单中失去样式:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <ribbon:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png" HorizontalAlignment="Left">
        <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                  x:Name="MenuItem9"
                                                  ImageSource="Images\LargeIcon.png"                                              
                                          />
    </ribbon:RibbonApplicationMenu>

</Grid>                                     
                                          />
    </ribbon:RibbonApplicationMenu>
于 2013-03-02T17:55:43.210 回答