I followed this article and some others to create a custom RoutedUICommand. I use the Infragistics feed, but I don't think the problem comes from there.
<igRibbon:XamRibbonWindow x:Class="MyRibbonWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igRibbon="http://infragistics.com/Ribbon" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:MyNamespaceTag="clr-namespace:MyNamespace" xmlns:igWPF="http://schemas.infragistics.com/xaml/wpf" mc:Ignorable="d" WindowState="Maximized"> <igRibbon:XamRibbonWindow.Resources> </igRibbon:XamRibbonWindow.Resources> <igRibbon:RibbonWindowContentHost x:Name="ribbonWindowContentHost" > <igRibbon:RibbonWindowContentHost.Ribbon> <igRibbon:XamRibbon x:Name="xamRibbon" Theme="[current]"> <igRibbon:XamRibbon.ApplicationMenu> <igRibbon:ApplicationMenu> <igRibbon:ApplicationMenu.FooterToolbar> <igRibbon:ApplicationMenuFooterToolbar> <igRibbon:ButtonTool Name="appMenuOptions" Caption="Opt_ions"/> </igRibbon:ApplicationMenuFooterToolbar> </igRibbon:ApplicationMenu.FooterToolbar> </igRibbon:ApplicationMenu> </igRibbon:XamRibbon.ApplicationMenu> </igRibbon:XamRibbon> </igRibbon:RibbonWindowContentHost.Ribbon> <ContentControl Content="{Binding MyContent}" ContentTemplateSelector="{StaticResource myContentTemplateSelector}" /> </igRibbon:RibbonWindowContentHost> </igRibbon:XamRibbonWindow>
We needed to change the look of the Infragistics feed, and a team member from the Infragistics community suggested adding a style. The problem is that when we added it to the "Resources" section of the tape, it did not work. Therefore, we were forced to do the following:
var resourceDictionary = new ResourceDictionary(); resourceDictionary.Source = new Uri( @"/MyNamespace;component/Resources/RibbonResources.xaml", UriKind.RelativeOrAbsolute); xamRibbon.Resources.MergedDictionaries.Add(resourceDictionary);
This is true for the styles on the tape, but in this RibbonResources.xaml we have a button:
<Button Name="myButton" Command="MyNamespaceTag:MyCommands.MyCommand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"> <Image Source="MyImage.png" Width="16" Height="16" /> </Button>
The MyCommand and MyCommands class was created exactly in the article that I mentioned. But when I run the application, I get the following error:
XamlParseException: Failed to create a "command" from the text MyNamespace: MyCommands.MyCommand 'InnerException: type reference cannot find a type named' {clr-namespace: MyNamespace} MyCommands'.
If instead I use the command:
Command="{x:Static MyNamespaceTag:MyCommands.MyCommand}"
I get the following exception:
XamlParseException: Specify a value for "System.Windows.Markup.StaticExtension" throws an exception. InnerException: a type reference cannot find a type named '{CLR names: MyNamespaces} MyCommands'.
In the code, we bind the command as follows:
CommandBindings.Add( new CommandBinding( MyCommands.MyCommand, Show, CanShow));
If we place the button directly where we have XamRibbonWindow, it works fine.
I'm still pretty new to WPF and I can't figure out what I'm doing wrong.