I am using the WPF ribbon CTP from Microsoft.
However, there is no sample. I am not sure where to start. The RibbonWindow does not have a property for the Ribbon. Does anyone have a sample that works?
If you're using the WPF Ribbon
http://msdn.microsoft.com/en-us/library/ff799534(v=vs.100).aspx
The MSDN documentation has good examples on how to use each component.
http://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon(v=vs.100).aspx
<r:RibbonWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
x:Class="MainWindowView"
Title="MainWindowView" Height="300" Width="515">
<DockPanel>
<r:Ribbon DockPanel.Dock="Top">
<r:RibbonTab x:Name="tab1" Header="Tab1">
<r:RibbonGroup Header="Group1">
<r:RibbonButton x:Name="button1" Label="Button 1" LargeImageSource="/Images/button1.png" />
<r:RibbonButton x:Name="button2" Label="Button 2" LargeImageSource="/Images/button2.png"/>
<r:RibbonButton x:Name="button3" Label="Button 3" LargeImageSource="/Images/Button3.png"/>
</r:RibbonGroup>
<r:RibbonGroup Header="Group2">
<r:RibbonButton x:Name="button4" Label="Button 4" LargeImageSource="/Images/button4.png"/>
</r:RibbonGroup>
<r:RibbonGroup Header="Group 3">
<r:RibbonMenuButton Label="Button 5" LargeImageSource="/Images/button5.png" >
<r:RibbonButton x:Name="button6" Label="Button 6" SmallImageSource="/Images/button6.png"/>
</r:RibbonMenuButton>
<r:RibbonMenuButton Label="Button 7" LargeImageSource="/Images/button7.png" >
<r:RibbonButton x:Name="button8" Label="Button 8" />
</r:RibbonMenuButton>
</r:RibbonGroup>
</r:RibbonTab>
</r:Ribbon>
</DockPanel>
</r:RibbonWindow>
The only gotcha is that you need to update your view to inherit from RibbonWindow instead of Window.
Related
In a nutshell, I need to provide a ribbon QuickAccessToolbar without the ribbon being visible. This is quite easily achieved, but a great problem for me is that the labels on the toolbar items are not visible. Here is my Ribbon:
<Ribbon x:Name="ShellRibbon" Grid.Row="0" IsMinimized="True">
<Ribbon.QuickAccessToolBar>
<RibbonQuickAccessToolBar>
<RibbonSplitButton x:Name ="Save" Label="Save" />
<RibbonSplitButton Label="Employee Access" LabelPosition="Header" >
<RibbonMenuItem Header="Undo action #1" />
<RibbonMenuItem Header="Undo action #2" />
<RibbonMenuItem Header="Undo action #3" />
</RibbonSplitButton>
</RibbonQuickAccessToolBar>
</Ribbon.QuickAccessToolBar>
<RibbonTab>
<RibbonButton Label="One"></RibbonButton>
</RibbonTab>
<RibbonTab></RibbonTab>
</Ribbon>
The RibbonMenuItem headers are visible when I drop down the RibbonSplitButton, but its header isn't visible, and neither that of the Save button. What am I doing wrong?
You have to place your ribbon controls inside a DockPanel :
<Ribbon.QuickAccessToolBar>
<RibbonQuickAccessToolBar>
<DockPanel>
<RibbonSplitButton x:Name ="Save" Label="Save" />
<RibbonSplitButton Label="Employee Access" LabelPosition="Header" >
<RibbonMenuItem Header="Undo action #1" />
<RibbonMenuItem Header="Undo action #2" />
<RibbonMenuItem Header="Undo action #3" />
</RibbonSplitButton>
</DockPanel>
</RibbonQuickAccessToolBar>
</Ribbon.QuickAccessToolBar>
I am using Microsoft's Ribbon of WPF 4.5 and developing application using VS2012 (C#) on Win 8 machine. I want to make my application show RibbonApplicationMenu like the "File"-menu of Office Word 2010, but I can't find out which control is used for it (see attached screenshot, red-marked control number 1 and 2). I also tried RibbonApplicationSplitMenuItem but it is more like Office old-style.
Maybe anyone can tell me. Thank you in advance.
1) I suggest you use the ribbon that's inside .net 4.5 (add a reference to System.Windows.Controls.Ribbon). I'm not sure what you used the external one.
2)What you need for a menu is Ribbon.ApplicationMenu
3) Below is a working ribbon (based on that) that includes several types of buttons as well as a menu that you require.
All you need for this to work is to add an images folder with an "options.png" in it.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ribbon SelectedIndex="0" Grid.Column="0" Grid.ColumnSpan="5">
<!-- Help Pane, located at the right-hand side -->
<Ribbon.HelpPaneContent>
<RibbonButton SmallImageSource="Images\options.png" />
</Ribbon.HelpPaneContent>
<!-- Quick Access Toolbar - located at the upper-left corner -->
<Ribbon.QuickAccessToolBar>
<RibbonQuickAccessToolBar>
<RibbonButton x:Name ="Save" SmallImageSource="Images\options.png" />
<RibbonSplitButton x:Name ="Undo" SmallImageSource="Images\options.png" >
<RibbonSplitMenuItem Header="Undo 1" />
<RibbonSplitMenuItem Header="Undo 2" />
</RibbonSplitButton>
<RibbonSplitButton x:Name="Redo" SmallImageSource="Images\options.png" >
<RibbonSplitMenuItem Header="Redo 1" />
<RibbonSplitMenuItem Header="Redo 2" />
</RibbonSplitButton>
<RibbonCheckBox Label="Sound" KeyTip="X" />
</RibbonQuickAccessToolBar>
</Ribbon.QuickAccessToolBar>
<!-- Application Menu, located at the left-hand side (down arrow) -->
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu KeyTip="F">
<RibbonApplicationMenuItem Header="Options1" ImageSource="Images\options.png" />
<RibbonApplicationMenuItem Header="Exit2" ImageSource="Images\options.png" />
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<!-- Ribbon Tab #1: Home -->
<RibbonTab Header="Home" KeyTip="H" >
<!-- Home group-->
<RibbonGroup x:Name="ClipboardGroup" Header="Home">
<RibbonMenuButton LargeImageSource="Images\options.png" Label="Activate" KeyTip="V">
<RibbonToggleButton SmallImageSource="Images\options.png" Label="blabla" KeyTip="H" />
<RibbonToggleButton SmallImageSource="Images\options.png" Label="option2" />
</RibbonMenuButton>
<RibbonToggleButton SmallImageSource="Images\options.png" Label="Toggle " KeyTip="X" />
<RibbonToggleButton x:Name="Toggle11" SmallImageSource="Images\options.png" Label="Just a Toggle" KeyTip="FP" />
</RibbonGroup>
<!-- Employee And Payroll group-->
<RibbonGroup x:Name="Employee" Header="Adjust View">
<RibbonMenuButton LargeImageSource="Images\options.png" Label="Test" KeyTip="V">
<RibbonMenuItem ImageSource="Images\options.png" Header="Keep Text Only" KeyTip="T"/>
<RibbonMenuItem ImageSource="Images\options.png" Header="Paste Special..." KeyTip="S"/>
</RibbonMenuButton>
<RibbonCheckBox SmallImageSource="Images\options.png" Label="Sound" KeyTip="X" />
</RibbonGroup>
</RibbonTab>
<!-- Ribbon Tab #2: Launch -->
<RibbonTab Header="Settings" KeyTip="I">
<!-- Launch/Applications group-->
<RibbonGroup Header="Settings">
<RibbonButton SmallImageSource="Images\options.png" Label="Record" KeyTip="C" />
</RibbonGroup>
</RibbonTab>
<RibbonTab Header="PageLayout" KeyTip="L">
<!-- Launch/Applications group-->
</RibbonTab>
</Ribbon>
</Grid>
</Window>
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu>
<RibbonApplicationMenu.AuxiliaryPaneContent>
<Label Content="Right panel!"></Label>
</RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonApplicationMenuItem Header="Exit" Click="ShutDown" />
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
haha
Finally I found the answer in wpf sample browser of infragistics netadvantage. The no. 1 is called "backstage" (ribbon 2010 style), no. 2 is a "application menu item".
(in my opinion) The infragistics' ribbon is easier to use than the Microsoft's one, since I can't find tutorial how to create backstage (ribbon 2010 style); the existing tutorials are mostly using old ribbon (2007 style).
Here take a look my simple code snippet:
<Window x:Class="TestRibbon.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:igRibbon="http://infragistics.com/Ribbon"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
Height="768"
Width="1024"
Title="Test Ribbon"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Grid x:Name="gridMain">
<igRibbon:XamRibbon x:Name="ribbonMain"
Width="Auto"
ApplicationMenuMode="Office2010"
ApplicationAccentColor="Blue">
<igRibbon:XamRibbon.ApplicationMenu2010>
<igRibbon:ApplicationMenu2010 Caption="File">
<igRibbon:ApplicationMenu2010Item KeyTip="I"
Header="Information">
<igRibbon:ApplicationMenu2010Item.Content>
<Grid Margin="20,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Margin="0,20,0,0" Foreground="Black" Text="IP" />
</StackPanel>
<StackPanel Grid.Column="1">
<TextBlock Margin="0,20,0,0" />
<TextBlock Foreground="DarkGray" Text="192.168.2.1" />
</StackPanel>
</Grid>
</igRibbon:ApplicationMenu2010Item.Content>
</igRibbon:ApplicationMenu2010>
</igRibbon:XamRibbon.ApplicationMenu2010>
</igRibbon:XamRibbon>
</Grid>
</window>
I am creating Ribbon Control for my application and for which I have already written most of code . The only problem I am facing is that the Ribbon Buttons I am adding to the Tabs are not aligning properly in the Tab . As you can see in the Screen Shot the button is aligning to bottom of the Tab. How can I bring these button to top so they are visible.
This is How my app looks like
The XAML Code is below
<UserControl x:Class="SongPurifier.UserControls.RibbonControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
>
<Grid>
<ribbon:Ribbon x:Name="ribbon" VerticalAlignment="Top">
<ribbon:RibbonTab Header="Home">
<ribbon:RibbonSplitButton
Label="Open"
LargeImageSource="/Images/Folder Open.png"
Command="{Binding OpenFolderCommand}">
</ribbon:RibbonSplitButton>
</ribbon:RibbonTab>
<ribbon:RibbonTab Header="Edit" >
<ribbon:RibbonButton Label="Replace String"
LargeImageSource="/Images/Find Replace.png"
Command="{Binding EditSongInfoCommand}"
>
</ribbon:RibbonButton >
<ribbon:RibbonButton Label="Update Song Info"
LargeImageSource="/Images/Update.png"
Command="{Binding UpdateSongInfoCommand}"
>
</ribbon:RibbonButton>
</ribbon:RibbonTab>
<ribbon:RibbonTab Header="Update" >
<ribbon:RibbonButton
Label="Check for Update" >
</ribbon:RibbonButton>
</ribbon:RibbonTab>
</ribbon:Ribbon>
</Grid>
Sachin:
Place your Ribbon Buttons inside a RibbonGroup.
<my:RibbonTab Header="Home">
<my:RibbonGroup Header="File">
<ribbon:RibbonSplitButton
Label="Open"
LargeImageSource="/Images/Folder Open.png"
Command="{Binding OpenFolderCommand}">
</ribbon:RibbonSplitButton>
</my:RibbonGroup>
</my:RibbonTab>
I'm using a Silverlight 4 page with an Accordion to which I'm trying to insert 2 user controls to each Accordion item.
<toolkit:Accordion Name="accordion1">
<toolkit:AccordionItem Content="item 1" Header="A">
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"> </local:AddRemoveControl>
</toolkit:AccordionItem>
<toolkit:AccordionItem Content="item 2" Header="B - long header">
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"> </local:DatesFilter>
</toolkit:AccordionItem>
</toolkit:Accordion>
I'm getting the following error message: "The property content is set more than once"
How can I proceed?
Thank you!
You can only have one content item in an accordion.
What you will need to do is wrap your controls in a StackPanel:
<toolkit:Accordion Name="accordion1">
<toolkit:AccordionItem Content="item 1" Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"> </local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
Here is my updated code:
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Content="item 1" Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
</StackPanel>
</toolkit:AccordionItem>
<toolkit:AccordionItem Content="item 2" Header="B - long header">
<StackPanel>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"></local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
You are defining the content twice. Try removing the content tags from the AccordionItem like this:
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
</StackPanel>
</toolkit:AccordionItem>
<toolkit:AccordionItem Header="B - long header">
<StackPanel>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"></local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
Also, the way you have it currently you will end up with two Accodion items with one control in each. To get both the controls in the same item you need to put the second control in the first stackpanel.
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0">
</local:AddRemoveControl>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76">
</local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
<r:RibbonWindow.Resources>
<ResourceDictionary>
<!--Ribbon Commands-->
<r:RibbonCommand x:Key="cmdPrint" CanExecute="RibbonCommand_CanExecute_Print" LabelTitle="Print" LabelDescription="Print" ToolTipTitle="Help" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />
<r:RibbonCommand x:Key="cmdExit" CanExecute="RibbonCommand_CanExecute_Close" LabelTitle="Close" LabelDescription="Close" ToolTipTitle="Help" ToolTipDescription="Close Application" SmallImageSource="Images\exitIcon.png" LargeImageSource="Images\exitIcon.png" />
<r:RibbonCommand x:Key="cmdHelp" CanExecute="RibbonCommand_CanExecute_Help" LabelTitle="About" LabelDescription="Help" ToolTipTitle="Help" ToolTipDescription="About Application" SmallImageSource="Images\vdiWorksIcon.png" LargeImageSource="Images\vdiWorksIcon.png" />
<!--Theme-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
<!--Root Grid-->
<Grid x:Name="LayoutRoot">
<r:Ribbon Title="Protocol Inspector" x:Name="ribbon" BorderBrush="Orange">
<r:Ribbon.SelectedTab>
<r:RibbonTab/>
</r:Ribbon.SelectedTab>
<!--Quick Access Toolbar-->
<r:Ribbon.QuickAccessToolBar>
<r:RibbonQuickAccessToolBar>
<r:RibbonButton Command="{StaticResource cmdExit}" />
<r:RibbonButton Command="{StaticResource cmdPrint}" />
<r:RibbonButton Command="{StaticResource cmdHelp}"/>
</r:RibbonQuickAccessToolBar>
</r:Ribbon.QuickAccessToolBar>
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu IsEnabled="True" >
<r:RibbonApplicationMenu.Command>
<r:RibbonCommand Executed="RibbonCommand_Executed" SmallImageSource="Images\VdiworksIcon.png" LargeImageSource="Images\VdiworksIcon.png" />
</r:RibbonApplicationMenu.Command>
<r:RibbonApplicationMenuItem Command="{StaticResource cmdPrint}" />
<r:RibbonApplicationMenuItem Command="{StaticResource cmdExit}" />
<r:RibbonApplicationMenuItem Command="{StaticResource cmdHelp}" />
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
<r:RibbonTab x:Name="HomeTab" Label="Home" IsSelected="True">
<r:RibbonGroup Name="FileGroup">
<r:RibbonGroup.Command>
<r:RibbonCommand LabelTitle="Home" />
</r:RibbonGroup.Command>
<r:RibbonButton Name="menuExit" Content="Exit" Command="{StaticResource cmdExit}"/>
<r:RibbonButton Name="menuPrint" Content="Print" Command="{StaticResource cmdPrint}"/>
</r:RibbonGroup>
</r:RibbonTab>
<r:RibbonTab x:Name="HelpTab" Label="Help">
<r:RibbonGroup Name="HelpGroup">
<r:RibbonGroup.Command>
<r:RibbonCommand LabelTitle="Help" />
</r:RibbonGroup.Command>
<r:RibbonButton Name="menuAbout" Content="About" Command="{StaticResource cmdHelp}"/>
</r:RibbonGroup>
</r:RibbonTab>
</r:Ribbon>
Menu options are not enabled, they are disabled.
100% working Correct Answer
<r:RibbonWindow.Resources>
<ResourceDictionary>
<r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdPrint" LabelTitle="Print" LabelDescription="Print" ToolTipTitle="Help" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />
<r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdExit" LabelTitle="Close" LabelDescription="Close" ToolTipTitle="Help" ToolTipDescription="Close Application" SmallImageSource="Images\exitIcon.png" LargeImageSource="Images\exitIcon.png" />
<r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdHelp" LabelTitle="About" LabelDescription="Help" ToolTipTitle="Help" ToolTipDescription="About Application" SmallImageSource="Images\ICON.png" LargeImageSource="Images\ICON.png" />
<r:RibbonCommand x:Key="testCmd" Executed="RibbonCommand_Executed" LabelTitle="Test Command" ToolTipDescription="test command" SmallImageSource="Images\ICON.png" LargeImageSource="Images\ICON.png"/>
<!--Theme-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
Instead of specifying CanExecute and Executed event handlers for the individual commands in the Resources tag, try specifying them as CommandBindings
<r:Ribbon Title="Protocol Inspector" x:Name="ribbon" BorderBrush="Orange">
<r:Ribbon.CommandBindings>
<CommandBinding Command="{StaticResource cmdExit}"
CanExecute="cmdExit_CanExecute"
Executed="cmdExit_Executed" />
</r:Ribbon.CommandBindings>
...