在 WPF 功能区中的 RibbonApplicationMenu 上添加 "File" 名称

Add "File" name on RibbonApplicationMenu in WPF Ribbon

我是制作 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>

就像这张图:

这里有一些可能的(虽然很复杂)解决方案: 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>

给你: