I am adding a RibbonTab dynamically to the Ribbon control (it is a contextual in natire i.e. it is displayed based on some conditions). In the Ribbon Tab I have defined a tool which I want to display in the Quick Access toolbar. So, I am setting the IsQatCommonTool property to "true".
On launching the application when the Ribbon Tab is displayed (based on some condition the Tab is displayed), the icon shows up in the "Customize Quick Access Toolbar" dropdown. But on selecting the option the toll is disabled.
This happens only for the RibbonTab items I am dynamically. Do I need to set some property other than IsQatCommonTool?
Thanks!
As long as the tool exists within the tab and the tab within the ribbon then it should be enabled. Can you post a sample demonstrating the problem?
It works if the tool uses an event. But if I use a RoutedUICommand in the tool the tool is disabled in the quick access toolbar.
Here is the sample code. As I mentioned earlier the Tool is disabled when a command is used but it works if an event handler for the click event is used instead.
This RibbonGroup is part of the RibbonTab which is added to the main ribbon in the code using XamRibbon.Tabs.Add()
Also, the same code works (with the command handler) if the RibbonTab is not added in the C# code but is added in the XAML directly as part of other RibbonTab's.
<igRibbon:RibbonGroup x:Class="TestApp.TestRibbon" 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:local="clr-namespace:TestApp">
<igRibbon:ToolHorizontalWrapPanel> <igRibbon:ButtonTool x:Name="btnTest" Id="btnTest" IsQatCommonTool="True" Caption="TestTool" Command="local:TestRibbon.TestCommand"/> </igRibbon:ToolHorizontalWrapPanel></igRibbon:RibbonGroup>
Test.xaml.cs:
public partial class TestRibbon : RibbonGroup { public static RoutedUICommand TestCommand;
public TestRibbon() { TestCommand = new RoutedUICommand("TestCommand", "TestCommand", typeof(TestRibbon));
CommandBinding cmd = new CommandBinding(TestCommand, ExecuteTest); this.CommandBindings.Add(cmd);
InitializeComponent();
}
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ExecuteTest(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("Test"); }
Unless I'm misreading this - the tool should be disabled. The only place that you are handling the CanExecute for that TestCommand is within the RibbonGroup (your derived RibbonGroup named TestRibbon). Therefore the only time that you would be setting e.CanExecute to true for that command is when the CanExecute bubbles up to the ribbon group. So if a tool outside the ribbongroup uses that command then nothing will handle the CanExecute and therefore CanExecute will be false and the button will consider itself disabled. Perhaps you could bind the CommandTarget to the containing ribbongroup so that all instances of the button will target that element.
Setting the CommandTarget to the containing ribbon worked. Thanks!