Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
CanExecute bindings in dropdown items of a Segmented MenuTool disable it always
posted

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"/>

        <CommandBinding

            Command="{x:Static l:Window1.Widget2Command}"

            Executed="Widget2Command_Executed"

            CanExecute="Widget2Command_CanExecute"

            />

            <!-- Delete the CanExecute setting above to re-enable the segmented MenuTool below -->

        <CommandBinding

            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"

                            Command="{x:Static l:Window1.Widget1Command}"

                            >

                            <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:RibbonGroup.MinimumSize="ImageOnly"

                                Command="{x:Static l:Window1.Widget2Command}"

                                >

                                <igRibbon:ButtonTool.ToolTip>

                                    <igRibbon:XamRibbonScreenTip FooterSeparatorVisibility="Collapsed">

                                        <igRibbon:XamRibbonScreenTip.Header>

                                            Type 2 Widget

                                        </igRibbon:XamRibbonScreenTip.Header>

                                        Do it to a type 2 Widget.

                                    </igRibbon:XamRibbonScreenTip>

                                </igRibbon:ButtonTool.ToolTip>

                            </igRibbon:ButtonTool>

 

                            <igRibbon:ButtonTool

                                Caption="Type 3 Widget"

                                SmallImage="Type3_Widget_Small.png"

                                LargeImage="Type3_Widget_Large.png"

                                igRibbon:RibbonGroup.MaximumSize="ImageAndTextNormal"

                                igRibbon:RibbonGroup.MinimumSize="ImageOnly"

                                Command="{x:Static l:Window1.Widget3Command}"

                                >

                                <igRibbon:ButtonTool.ToolTip>

                                    <igRibbon:XamRibbonScreenTip FooterSeparatorVisibility="Collapsed">

                                        <igRibbon:XamRibbonScreenTip.Header>

                                            Type 3 Widget

                                        </igRibbon:XamRibbonScreenTip.Header>

                                        Do it to a type 3 Widget.

                                    </igRibbon:XamRibbonScreenTip>

                                </igRibbon:ButtonTool.ToolTip>

                            </igRibbon:ButtonTool>

                        </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);

            e.Handled = true;

        }

 

        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);

            e.Handled = true;

        }

 

        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);

        }

    }

}

   
Parents
  • 54937
    Offline posted

    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?

Reply Children