How to start using Ribbons in WPF

会有一股神秘感。 提交于 2019-12-03 20:19:23
Tinaira

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>

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

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.

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

Remove reference like System.Window.Shell and RibbonControlLibrary

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!