首页 > 解决方案 > 在 WPF 功能区的 RibbonApplicationMenu 上添加“文件”名称

问题描述

我是制作 WPF 项目的新手。

我搜索了如何在其中添加文本,RibbonApplicationMenu也许看起来,在这个网站上有同样的问题,但相信我,我实现了它,但在我身上不起作用。

我试过在我的文件中添加一个“文件”名称,<RibbonApplicationMenu>Label="File"它不起作用。接下来我可以尝试什么?

这是我的 XAML 代码:

             <Ribbon x:Name="Ribbon">
                    <Ribbon.TitleTemplate>
                        <DataTemplate >
                            <TextBlock x:Name="FrontPageTitle" TextAlignment="Center" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Ribbon}}, Path=Title}" Width="{Binding ElementName=RibbonWindow, Path=ActualWidth}" />
                        </DataTemplate>
                    </Ribbon.TitleTemplate>
                    <Ribbon.HelpPaneContent>
                        <RibbonButton SmallImageSource="pack://application:,,,/MYSEP;component/Images/window.png" />
                    </Ribbon.HelpPaneContent>
                    <Ribbon.QuickAccessToolBar>
                        <RibbonQuickAccessToolBar>
                            <RibbonButton x:Name="QATButton1" 
                                         SmallImageSource="pack://application:,,,/MYSEP;component/Images/window.png" />
                            <RibbonButton x:Name="QATButton2" 
                                         SmallImageSource="pack://application:,,,/MYSEP;component/Images/window.png" />
                        </RibbonQuickAccessToolBar>
                    </Ribbon.QuickAccessToolBar>
                    <Ribbon.ApplicationMenu>
                        <RibbonApplicationMenu Label="File">
                            <RibbonApplicationMenuItem Header="New Design Project"
                                                      x:Name="NewDesignProject"
                                                      ImageSource="pack://application:,,,/MYSEP;component/Images/newProject.png" Click="AddNewDesign"/>
                            <RibbonApplicationMenuItem Header="New Rating Project"
                                                      x:Name="NewRatingProject"
                                                      ImageSource="pack://application:,,,/MYSEP;component/Images/newProject.png" Click="AddNewRating"/>
                            <RibbonApplicationMenuItem Header="Open..."
                                                       x:Name="Open"
                                                       ImageSource="pack://application:,,,/MYSEP;component/Images/open.png" Click="OpenMysepProject"/>
                        </RibbonApplicationMenu>
                    </Ribbon.ApplicationMenu>
                    <RibbonTab x:Name="HomeTab" 
                              Header="Home">
                        <RibbonGroup x:Name="Group1" 
                                    Header="Project">
                            <RibbonButton x:Name="Button1"
                                         LargeImageSource="pack://application:,,,/MYSEP;component/Images/manageProject.png"
                                         Label="Manage Project" />
                        </RibbonGroup>
                        <RibbonGroup x:Name="Group2" 
                                    Header="Vessel">
                            <RibbonButton x:Name="Button2"
                                         LargeImageSource="pack://application:,,,/MYSEP;component/Images/addVessel.png"
                                         Label="Add Vessel Design Mode" />
                            <RibbonButton x:Name="Button3"
                                         LargeImageSource="pack://application:,,,/MYSEP;component/Images/info.png"
                                         Label="Add Vessel Rating Mode" />
                            <RibbonButton x:Name="Button4"
                                         LargeImageSource="pack://application:,,,/MYSEP;component/Images/delete.png"
                                         Label="Delete Vessel" />
                        </RibbonGroup>
                    </RibbonTab>
              </Ribbon>

就像这张图片:

在此处输入图像描述

标签: c#wpfxamlribbon

解决方案


这里有许多可能(虽然很复杂)的解决方案: How to set text at the head of a RibbonApplicationMenu

编辑

我测试了自己,只需在之后立即添加<RibbonApplicationMenu>

<RibbonApplicationMenu.SmallImageSource>
    <DrawingImage>
        <DrawingImage.Drawing>
            <GeometryDrawing>
                <GeometryDrawing.Geometry>
                    <RectangleGeometry Rect="0,0,20,20"></RectangleGeometry>
                </GeometryDrawing.Geometry>
                <GeometryDrawing.Brush>
                    <VisualBrush Stretch="Uniform">
                        <VisualBrush.Visual>
                            <TextBlock Text="File" FontSize="16" Foreground="White" />
                        </VisualBrush.Visual>
                    </VisualBrush>
                </GeometryDrawing.Brush>
            </GeometryDrawing>
        </DrawingImage.Drawing>
    </DrawingImage>
</RibbonApplicationMenu.SmallImageSource>

给你:

在此处输入图像描述


推荐阅读