如何开始在 WPF 中使用功能区 [英] How to start using Ribbons in WPF

查看:54
本文介绍了如何开始在 WPF 中使用功能区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我不想使用像

以及 XAML 文件中的这个命名空间:

并尝试使用此代码示例:

 <Ribbon DockPanel.Dock=顶部"边距=0,-22,0,0"><Ribbon.ApplicationMenu><RibbonApplicationMenu SmallImageSource="Images/list.png"><RibbonApplicationMenu.AuxiliaryPaneContent><RibbonGallery ScrollViewer.VerticalScrollBarVisibility="Auto"><RibbonGalleryCategory MaxColumnCount=1"><RibbonGalleryItemx:Name=GalleryItem1"内容=应用程序菜单内容"MouseOverBackground=透明"MouseOverBorderBrush=透明"CheckedBackground=透明"CheckedBorderBrush =透明"/><RibbonGalleryItem><超链接 x:Name="hl1";Click=hl1_Click"><Run Text="http://www.bing.com"/></超链接></RibbonGalleryItem></RibbonGalleryCategory></RibbonGallery></RibbonApplicationMenu.AuxiliaryPaneContent><RibbonApplicationMenuItem x:Name="menuItem1";标题=添加"ImageSource=Images/add.png"/><RibbonApplicationMenuItem x:Name="menuItem2";标题=设置"ImageSource=Images/system_preferences.png"/><RibbonApplicationMenu></Ribbon.ApplicationMenu><RibbonTab x:Name=rbnTab1";标题=Tab1"><RibbonGroup x:Name="rbnGr1";标题=一般"><RibbonButton x:Name="btnRibbon1";标签=保存"LargeImageSource=Images/filesave.png"/><RibbonButton x:Name="btnRibbon2";标签=打开"LargeImageSource=Images/load.png"/></RibbonGroup><RibbonGroup x:Name=rbnGr2";标题=新组"><RibbonButton x:Name="btnRibbon3";标签=字体"LargeImageSource=Images/fonts.png"/><RibbonButton x:Name="btnRibbon4";标签=删除"LargeImageSource=Images/recycle_bin.png"/></RibbonGroup></RibbonTab><RibbonTab x:Name=rbnTab2";标题=Tab2"><RibbonGroup x:Name="rbnGr3";标题=其他组"><RibbonButton x:Name="btnRibbon5";标签=播放"LargeImageSource=Images/play.png"/><RibbonButton x:Name="btnRibbon6";标签=列表"LargeImageSource=Images/kmenuedit.png"/></RibbonGroup><RibbonGroup x:Name="rbnGr4";标题=什么是组"><RibbonButton x:Name="btnRibbon7";标签=睡眠"LargeImageSource=Images/icon_sleep.png"/><RibbonButton x:Name="btnRibbon8";标签=添加"LargeImageSource=Images/add.png"/></RibbonGroup></RibbonTab></功能区><网格><!-- 在此处添加您的内容--></网格></DockPanel>

如果您不喜欢,可以通过添加此属性删除Visibility=Collapsed"

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

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 quickaccesstoolbar and menuitem does 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.

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

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.

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.

解决方案

Add this reference:

and this namespace in the XAML file:

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>
    <RibbonApplicationMenu Visibility="Collapsed">
    </RibbonApplicationMenu>
</Ribbon.ApplicationMenu>

这篇关于如何开始在 WPF 中使用功能区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆