PopupButton allways enabled when using binding to MenuItems

Ribbon for WPF Forum

Posted 16 years ago by Kris Goossens - Remmicom
Version: 4.0.0457
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
We first used a fixed list of menu items on a popup button and this worked fine : When all menu-items where disabled, the popup button was disabled.

When we made the menu items dynamic with a binding to a menu item collection, the popup button allways stays enabled. Even if all menu-items are disabled.

Thx.


Xaml :
<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"    
    xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
    Title="Window1" Height="300" Width="400">
    
    <Window.CommandBindings>
        <CommandBinding Command="Copy" Executed="CopyThis" CanExecute="CopyThis_CanExecute"/>
    </Window.CommandBindings>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ribbon:Group Label="Group" >
            
            <!--Ok-->
            <ribbon:Button Label="Button"
                           Command="Copy"/>

            <!--Ok-->
            <ribbon:PopupButton Label="PopupButton with fixed menu items" 
                                Command="ApplicationCommands.NotACommand">
                <ribbon:Menu>
                    <ribbon:Button Label="Menu 1" Command="Copy"/>
                    <ribbon:Button Label="Menu 2" Command="Paste"/>
                </ribbon:Menu>
            </ribbon:PopupButton>

            <!--Not Ok, PopupButton allways enabled-->
            <ribbon:PopupButton Label="PopupButton with binding"
                                Command="ApplicationCommands.NotACommand"
                                AutoDisableWhenPopupContentIsDisabled="True"><!--or False-->
                <ribbon:Menu ItemsSource="{Binding MenuItems}"/>
            </ribbon:PopupButton>

        </ribbon:Group>
        
        <TextBlock Grid.Row="1" Text="Type text:"/>
        <TextBox x:Name="MyTextBox" Grid.Row="2"/>

    </Grid>
</Window>
The VB code :

Class Window1 

    Private Sub CopyThis(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
        MessageBox.Show("CopyThis command activated")
    End Sub

    Private Sub CopyThis_CanExecute(ByVal sender As System.Object, ByVal e As System.Windows.Input.CanExecuteRoutedEventArgs)
        If MyTextBox Is Nothing Then
            e.CanExecute = False
        Else
            e.CanExecute = (MyTextBox.Text > "")
        End If
    End Sub

    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.DataContext = Me
    End Sub

    Public Function GetMenuItems() As MenuItem()
        Dim _menuItems(3) As MenuItem
        For i As Int32 = 0 To 2
            _menuItems(i) = New MenuItem
            _menuItems(i).Header = "Menu from code " & i.ToString
            _menuItems(i).Command = ApplicationCommands.Copy
        Next i
        Return _menuItems
    End Function

    Public ReadOnly Property MenuItems() As MenuItem()
        Get
            Return GetMenuItems()
        End Get
    End Property

End Class

Comments (2)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kris,

Can you wrap this up in a simple project that repros the issue and email that over to our support address? Please reference this post in your email. Thanks!


Actipro Software Support

Posted 16 years ago by Kris Goossens - Remmicom
Avatar
Hi,

I should have been adding ActiproSoftware.Windows.Controls.Ribbon.Controls.Button controls instead of MenuItem.

Just tested Actipro 4.5.0471 with Button in stead of MenuItem and it works fine now.

If all buttons are disabled, the PopupButton is disabled too.

Thanks
Kris
The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.