5

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.

Zuoanqh
  • 942
  • 4
  • 10
  • 26
  • Incidentally, is the problem that these controls do not work in the designer, or do they not work at all? (Not an MS dev, so cannot help, but might be worth clarifying). – halfer Sep 15 '15 at 21:34
  • You are reading a link that tells you how to implement the control on WINFORM but your title saying otherwise. Can you confirm you wanna work on which kinda GUI. I'm sorry that I also kinda think the version of VS shouldn't be a problem. I would've look into more if you are talking about different .NET version but VS version shouldn't be a part of a problem. One thing to mention, I bet high percentage of WPF developer never rely on the design view. We just type the awful xmal code directly. – cscmh99 Sep 16 '15 at 03:22
  • @cscmh99 I want a solution that works in WPF's designer. I can and have done interface without a designer, but I think that should be when all others fail. Designer also reduce the amount of code you need to produce, therefore increase productivity and reduce bugs, when it's working (lol). I have actually did try XAML editing, copying codes around, and it does not work in the exact way designer does not work. – Zuoanqh Sep 16 '15 at 06:14
  • But i'm adding that information to the question now. – Zuoanqh Sep 16 '15 at 06:14

2 Answers2

13

Add this reference:

reference

and this namespace in the XAML file:

namespace

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>
Toni
  • 1,555
  • 4
  • 15
  • 23
Tinaira
  • 727
  • 2
  • 7
  • 23
2

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

cscmh99
  • 2,701
  • 2
  • 15
  • 18
  • This is an outdated hack. I really wanted something that adds to the designer, a native solution with all the support that should be there. if i'm going to write the entire ribbon using code without help, might as well just reinvent ribbons. besides, I see there's the ribbon tab if I do "show all" in the toolbox. I see there's old tutorials where it works perfectly with the designer. how come it get's worse as you upgrade from 3.5? It just dont feel like the right track for something basic as ribbons. – Zuoanqh Sep 16 '15 at 13:25
  • I don't know what you are after. The Ribbon is a stand-alone control provided by Mircosoft and as a part of .NET Framework 4.5. https://msdn.microsoft.com/en-us/library/ff799534(v=vs.110).aspx. So, I'm not sure what you mean about old/new hack. I know I'm not an ultimate expert for wpf but I have told you that you should NOT rely on designer when developing WPF application. Let me put it this way. Mircosoft came up with another tools called Blend to handle the "designer view" for crying out loud and it STILL not work well in most of the WPF project – cscmh99 Sep 16 '15 at 14:06
  • Upvoted for helpfulness, but are there not more recent resources on the MS site than 2010? That seems rather old. – halfer Sep 16 '15 at 19:56
  • I feel I had to repeat myself a lot. it used to work! i see video it's working with designers! why can't I get some of that? – Zuoanqh Sep 16 '15 at 21:41