如何开始在 WPF 中使用 Ribbon

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32595076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:25:09  来源:igfitidea点击:

How to start using Ribbons in WPF

wpfribbon

提问by Zuoanqh

I tried referencing the System.Windows.Controls.Ribbon, the toolbox tab does not show up. If I right-click a tab and click show all, the tab is there, but controls aren't light up. I can add a tab and controls related manually, but after adding the ribbon, things like quickaccesstoolbarand menuitemdoes not work properly - they are being treated as tabs for some reason. Control groups don't work as well. Simply nothing works as it's supposed to.

我尝试引用System.Windows.Controls.Ribbon,工具箱选项卡没有显示。如果我右键单击一个选项卡并单击全部显示,则该选项卡在那里,但控件没有亮起。我可以手动添加一个选项卡和相关控件,但是在添加功能区后,诸如quickaccesstoolbar和 之类的东西menuitem无法正常工作 - 由于某种原因,它们被视为选项卡。控制组也不起作用。根本没有任何事情像它应该的那样工作。

I have tried editing XAML directly. It fails in the same manner as using the designer.

我试过直接编辑 XAML。它以与使用设计器相同的方式失败。

The tutorials online are either outdated, for a paid control suite, or simply don't work.

对于付费控制套件,在线教程要么已经过时,要么根本不起作用。

I don't want to use mark-up solutions like http://www.codeproject.com/Articles/364272/Easily-Add-a-Ribbon-into-a-WinForms-Application-Cs, I want something that works in a designer -- Is that too much to ask? If so I'll gladly go back to winforms.

我不想使用像http://www.codeproject.com/Articles/364272/Easily-Add-a-Ribbon-into-a-WinForms-Application-Cs这样的标记解决方案,我想要一些可以在设计师——这要求太多了吗?如果是这样,我很乐意回到 winforms。

If you work with ribbons, how did you do it? This question seems simple, but after digging for hours I still don't have an answer.

如果你使用丝带,你是怎么做到的?这个问题看起来很简单,但挖了几个小时后我仍然没有答案。

I'm an individual developer, making an open source, free software. As a student I really can't afford 1000$ control suites. I use VS2013 community, I tried using 2015 instead, but all the problems above are the same.

我是一名个人开发人员,正在制作开源免费软件。作为一名学生,我真的买不起 1000 美元的控制套件。我使用VS2013社区,我尝试使用2015代替,但以上所有问题都是相同的。

回答by Tinaira

add this reference reference

添加此参考 参考

and this namespace in the xaml file enter image description here

以及 xaml 文件中的这个命名空间 在此处输入图片说明

and try working with this code example:

并尝试使用此代码示例:

 <DockPanel>
    <Ribbon DockPanel.Dock="Top" Margin="0,-22,0,0">  
        <Ribbon.ApplicationMenu>
            <RibbonApplicationMenu SmallImageSource="Images/list.png">

                <RibbonApplicationMenu.AuxiliaryPaneContent>
                    <RibbonGallery ScrollViewer.VerticalScrollBarVisibility="Auto">
                        <RibbonGalleryCategory MaxColumnCount="1">
                            <RibbonGalleryItem x:Name="GalleryItem1" Content="Application menu content" 
                                MouseOverBackground="Transparent"
                                MouseOverBorderBrush="Transparent"
                                CheckedBackground="Transparent"
                                CheckedBorderBrush="Transparent"
                                               />
                            <RibbonGalleryItem>
                                <Hyperlink x:Name="hl1" Click="hl1_Click">
                                    <Run Text="http://www.bing.com"/>
                                </Hyperlink>
                            </RibbonGalleryItem>
                        </RibbonGalleryCategory>
                    </RibbonGallery>
                </RibbonApplicationMenu.AuxiliaryPaneContent>
                <RibbonApplicationMenuItem x:Name="menuItem1" Header="Add" ImageSource="Images/add.png"/>
                <RibbonApplicationMenuItem x:Name="menuItem2" Header="Settings"
                                           ImageSource="Images/system_preferences.png"/>

            </RibbonApplicationMenu>
        </Ribbon.ApplicationMenu>

        <RibbonTab x:Name="rbnTab1" Header="Tab1">
            <RibbonGroup x:Name="rbnGr1" Header="General">
                <RibbonButton x:Name="btnRibbon1" Label="Save" LargeImageSource="Images/filesave.png"/>
                <RibbonButton x:Name="btnRibbon2" Label="Open" LargeImageSource="Images/load.png"/>
            </RibbonGroup>
            <RibbonGroup x:Name="rbnGr2" Header="New group">
                <RibbonButton x:Name="btnRibbon3" Label="Font" LargeImageSource="Images/fonts.png"/>
                <RibbonButton x:Name="btnRibbon4" Label="Delete" LargeImageSource="Images/recycle_bin.png"/>
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab x:Name="rbnTab2" Header="Tab2">
            <RibbonGroup x:Name="rbnGr3" Header="Other Group">
                <RibbonButton x:Name="btnRibbon5" Label="Play" LargeImageSource="Images/play.png"/>
                <RibbonButton x:Name="btnRibbon6" Label="List" LargeImageSource="Images/kmenuedit.png"/>
            </RibbonGroup>
            <RibbonGroup x:Name="rbnGr4" Header="What a group">
                <RibbonButton x:Name="btnRibbon7" Label="Sleep" LargeImageSource="Images/icon_sleep.png"/>
                <RibbonButton x:Name="btnRibbon8" Label="Add" LargeImageSource="Images/add.png"/>
            </RibbonGroup>
        </RibbonTab>
    </Ribbon>

    <Grid>
        <!-- add your content here-->

    </Grid>
</DockPanel>

you can remove the <Ribbon.ApplicationMenu>if you don't like it by addin this property Visibility="Collapsed"

<Ribbon.ApplicationMenu>如果您不喜欢它,您可以通过添加此属性来删除它Visibility="Collapsed"

<Ribbon.ApplicationMenu>
            <RibbonApplicationMenu Visibility="Collapsed">
            </RibbonApplicationMenu>
        </Ribbon.ApplicationMenu>

回答by cscmh99

Please take a look at the following. You should be able to have a very basic idea about Ribbon.

请看以下内容。您应该能够对 Ribbon 有一个非常基本的了解。

http://blogs.msdn.com/b/wpf/archive/2010/08/03/introducing-microsoft-ribbon-for-wpf.aspx

http://blogs.msdn.com/b/wpf/archive/2010/08/03/introducing-microsoft-ribbon-for-wpf.aspx

Sample project download

示例项目下载

If you want to run the project, you need to change the project's .NET Framework version to 4.0 or above.

如果要运行项目,需要将项目的.NET Framework版本改为4.0以上。

Add System.Window.Controls.Ribbon reference to the project

向项目添加 System.Window.Controls.Ribbon 引用

Remove reference like System.Window.Shell and RibbonControlLibrary

删除 System.Window.Shell 和 RibbonControlLibrary 等引用

The sample should be able to run after you fixed all the namespaces in xmal and the codebehind .cs

在修复 xmal 中的所有命名空间和代码隐藏 .cs 后,该示例应该能够运行

http://blogs.msdn.com/b/wpf/archive/2010/08/03/building-a-simple-ribbon-application-in-wpf.aspx

http://blogs.msdn.com/b/wpf/archive/2010/08/03/building-a-simple-ribbon-application-in-wpf.aspx

Microsoft Ribbon for WPF(Get the one with Sample for more comprehensive sample) http://www.microsoft.com/en-us/download/details.aspx?id=11877

Microsoft Ribbon for WPF(获取带有示例的更全面示例) http://www.microsoft.com/en-us/download/details.aspx?id=11877