简体   繁体   English

WPF中的Ribbon-Like控件

[英]Ribbon-Like Control in WPF

I'm trying to create some drop-downs for a toolbar and want them to look like the Page Layout drop-downs in Word (such as the Orientation and Size menus). 我正在尝试为工具栏创建一些下拉菜单,并希望它们看起来像Word中的页面布局下拉菜单(例如“方向”和“大小”菜单)。

I've attempted to do this using a ComboBox, but I can't figure out how to show the option name, rather than the selected item at the top of the ComboBox. 我试图使用ComboBox来做这件事,但我无法弄清楚如何显示选项名称,而不是ComboBox顶部的选定项目。 Is it possible to make the ComboBox show whatever you want it to at the top? 是否有可能让ComboBox在顶部显示您想要的任何内容?

Should I be trying to do this with a ComboBox or is there a better way to go about this? 我应该尝试使用ComboBox来做这件事还是有更好的方法来解决这个问题?

替代文字
(source: mstipsandtricks.com ) (来源: mstipsandtricks.com

EDIT: It looks like I need a Ribbon control. 编辑:看起来我需要一个Ribbon控件。 Can I make a simple one out of a ComboBox? 我可以用ComboBox制作一个简单的吗? It seems like I'm close, I just need to be able to display a category in the ComboBox instead of the selected item. 看起来我很接近,我只需要能够在ComboBox中显示一个类别而不是所选项目。

Word uses the Ribbons. Word使用Ribbon。

Here is the WPF Ribbons project . 这是WPF Ribbons项目 This will have a way to do what you are looking for. 这将有办法做你想要的。

You can build this using a combo box if you want, take a look at the ComboBox ControlTemplate example at: http://msdn.microsoft.com/en-us/library/ms752094.aspx 如果需要,可以使用组合框构建它,请查看ComboBox ControlTemplate示例: http//msdn.microsoft.com/en-us/library/ms752094.aspx

You can see in that page that the combobox is composed of a toggle button, a popup, a text box and a content presenter (only one of the last two is visible, depending on the combobox mode). 您可以在该页面中看到组合框由切换按钮,弹出窗口,文本框和内容呈现器组成(最后两个中只有一个是可见的,具体取决于组合框模式)。

You can remove the text box and the content presenter from the combobox template and replace them with whatever you want - for example, a big icon and the option name. 您可以从组合框模板中删除文本框和内容呈现器,并将其替换为您想要的任何内容 - 例如,大图标和选项名称。

You can also use the same technique of toggle button bound to a popup to create your own (non-combobox) drop down control. 您还可以使用与弹出窗口绑定的切换按钮相同的技术来创建自己的(非组合框)下拉控件。

我自己没有尝试过,但WPF“ Fluent Ribbon Control Suite ”本周早些时候被添加到Visual Studio Gallery中。

here is an example how to use ribbon by writing xaml code. 这里是一个如何通过编写xaml代码来使用功能区的示例。 it's very easy once you get used to it. 一旦你习惯它,这很容易。

first add this reference: 首先添加此引用: 在此输入图像描述

then add this namespace into the xaml file: 然后将此命名空间添加到xaml文件中:

在此输入图像描述

and now use this code template to work with: 现在使用此代码模板来处理:

<DockPanel>
    <ribbon: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="C# developer" 
                                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>
        <!--Rider-->
        <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:Ribbon>

    <Grid>
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/>

    </Grid>
</DockPanel>

if you want to hide the <Ribbon.ApplicationMenu> just add the following property: <Ribbon.ApplicationMenu> <RibbonApplicationMenu Visibility="Collapsed"> </RibbonApplicationMenu> </Ribbon.ApplicationMenu> 如果要隐藏<Ribbon.ApplicationMenu>只需添加以下属性: <Ribbon.ApplicationMenu> <RibbonApplicationMenu Visibility="Collapsed"> </RibbonApplicationMenu> </Ribbon.ApplicationMenu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM