Hi,
Using NetAdvantage for WPF Vol 2 Beta and Xamribbon Nov CTP with VS 2008 RTM
If I have a segmented MenuTool bound to a command and a number of ButtonTools in the dropdown that bind to commands, the segmented MenuTool will NEVER be enabled regardless of what the CanExecutes for all the command bindings (MenuTool or dropdown items, in this case ButtonTool) return. If however I remove one of the CanExecute bindings for one of the dropdown commands, everything starts to work properly. The following simple app illustrates. A couple of buttons in the window drive what the various dropdown command binding CanExecutes return. Running as-is for me always shows the Ribbon button disabled, regardless of the button states for the "Enable Type2" and "Enable Type3" buttons. If however I delete the CanExecute setting located above the line:
<!-- Delete the CanExecute setting above to re-enable the segmented MenuTool below -->
in the XAML, the Type3 dropdown enable state will depend on the "Enable Type3" button state, as I would expect.
Xaml
<igRibbon:XamRibbonWindow x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:WpfApplication2"
xmlns:igRibbon="http://infragistics.com/Ribbon"
xmlns:igEditors="http://infragistics.com/Editors"
xmlns:igWindows="http://infragistics.com/Windows"
Title="Window1"
SizeToContent="WidthAndHeight"
ResizeMode="CanResizeWithGrip"
>
<!-- ================================================================================================= -->
<!-- Command Bindings -->
<igRibbon:XamRibbonWindow.CommandBindings>
<CommandBinding
Command="{x:Static l:Window1.Widget1Command}"
Executed="Widget1Command_Executed"
CanExecute="Widget1Command_CanExecute"/>
Command="{x:Static l:Window1.Widget2Command}"
Executed="Widget2Command_Executed"
CanExecute="Widget2Command_CanExecute"
/>
Command="{x:Static l:Window1.Widget3Command}"
Executed="Widget3Command_Executed"
CanExecute="Widget3Command_CanExecute"/>
</igRibbon:XamRibbonWindow.CommandBindings>
<!-- Office Ribbon -->
<igRibbon:XamRibbonWindow.Ribbon>
<igRibbon:XamRibbon x:Name="m_XamRibbon">
<igRibbon:XamRibbon.Tabs>
<igRibbon:RibbonTabItem Header="Home">
<igRibbon:RibbonGroup Caption="Widgets">
<igRibbon:MenuTool
Caption="Widget"
ButtonType="Segmented"
SmallImage="Type1_Widget_Small.png"
LargeImage="Type1_Widget_Large.png"
igRibbon:RibbonGroup.MaximumSize="ImageAndTextLarge"
igRibbon:RibbonGroup.MinimumSize="ImageOnly"
<igRibbon:MenuTool.ToolTip>
<igRibbon:XamRibbonScreenTip FooterSeparatorVisibility="Collapsed">
<igRibbon:XamRibbonScreenTip.Header>
Type 1 Widget
</igRibbon:XamRibbonScreenTip.Header>
Do it to a type 1 Widget.
</igRibbon:XamRibbonScreenTip>
</igRibbon:MenuTool.ToolTip>
<igRibbon:ButtonTool
Caption="Type 2 Widget"
SmallImage="Type2_Widget_Small.png"
LargeImage="Type2_Widget_Large.png"
igRibbon:RibbonGroup.MaximumSize="ImageAndTextNormal"
<igRibbon:ButtonTool.ToolTip>
Type 2 Widget
Do it to a type 2 Widget.
</igRibbon:ButtonTool.ToolTip>
</igRibbon:ButtonTool>
Caption="Type 3 Widget"
SmallImage="Type3_Widget_Small.png"
LargeImage="Type3_Widget_Large.png"
Type 3 Widget
Do it to a type 3 Widget.
</igRibbon:MenuTool>
</igRibbon:RibbonGroup>
</igRibbon:RibbonTabItem>
</igRibbon:XamRibbon.Tabs>
</igRibbon:XamRibbon>
</igRibbon:XamRibbonWindow.Ribbon>
<DockPanel LastChildFill="False">
<ToggleButton Height="23" Name="button2" DockPanel.Dock="Top" >Enable Type2</ToggleButton>
<ToggleButton Height="23" Name="button3" DockPanel.Dock="Top" >Enable Type3</ToggleButton>
</DockPanel>
</igRibbon:XamRibbonWindow>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Infragistics.Windows.Ribbon;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : XamRibbonWindow
public static RoutedUICommand Widget1Command = new RoutedUICommand();
public static RoutedUICommand Widget2Command = new RoutedUICommand();
public static RoutedUICommand Widget3Command = new RoutedUICommand();
public Window1()
InitializeComponent();
}
private void Widget1Command_Executed(object sender, ExecutedRoutedEventArgs e)
Console.WriteLine("{0} Widget1Command_Executed", DateTime.Now.Ticks);
e.Handled = true;
private void Widget1Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = true;
Console.WriteLine("{0} Widget1Command_CanExecute {1}", DateTime.Now.Ticks, e.CanExecute);
private void Widget2Command_Executed(object sender, ExecutedRoutedEventArgs e)
Console.WriteLine("{0} Widget2Command_Executed", DateTime.Now.Ticks);
private void Widget2Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = (this.button2 != null) && (this.button2.IsChecked == true);
Console.WriteLine("{0} Widget2Command_CanExecute {1}", DateTime.Now.Ticks, e.CanExecute);
private void Widget3Command_Executed(object sender, ExecutedRoutedEventArgs e)
Console.WriteLine("{0} Widget3Command_Executed", DateTime.Now.Ticks);
private void Widget3Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = (this.button3 != null) && (this.button3.IsChecked == true);
Console.WriteLine("{0} Widget3Command_CanExecute {1}", DateTime.Now.Ticks, e.CanExecute);
Hi Terry. I just wanted to get some clarification. Are you saying that even when you enable one of the commands associated with the menu items, the menu is still not enabled or are you just trying to get the menu to be enabled even if all of the menu items are disabled?
igandrews said: Hi Terry. I just wanted to get some clarification. Are you saying that even when you enable one of the commands associated with the menu items, the menu is still not enabled or are you just trying to get the menu to be enabled even if all of the menu items are disabled?
The former, not the later. To be precise, the whole segmented MenuTool shown in the Ribbon is not enabled. But as I have mentioned in the original post, the MenuTool being disabled always depends on there being CanExecute bindings for all the menu items (ButtonTools) for the segmented MenuTool , and it does not depend at all on what the CanExecutes return. As the XAML/code that I originally posted can show, if you delete the CanExecute binding for one of the ButtonTools, the MenuTool has a chance of being enabled under some conditions.
I wouldn't mind if the code demonstrated that the segmented MenuTool shown in the Ribbon was disabled if all the menu item (ButtonTools) CanExecutes were set to return false. I do see a problem when the CanExecutes for the MenuTool and every menu item (ButtonTools) for its lower half is set to return true but the MenuTool shown in the ribbon stays disabled. This is what the demonstration code that I originally posted shows.
Thanks for the add'l info. I thought that was what you were asking but I wanted to make sure. It is correct that the menu tool (both the button and the dropdown portion) would be disabled when all the menu items it contains are disabled. However it should (and does with the latest internal version) enable when one or more of its child menu items is enabled so you should see this fix with the release version.