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


Xaml :
<Window x:Class="Window1"
    Title="Window1" Height="300" Width="400">
        <CommandBinding Command="Copy" Executed="CopyThis" CanExecute="CopyThis_CanExecute"/>
            <RowDefinition Height="100"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>

        <ribbon:Group Label="Group" >
            <ribbon:Button Label="Button"

            <ribbon:PopupButton Label="PopupButton with fixed menu items" 
                    <ribbon:Button Label="Menu 1" Command="Copy"/>
                    <ribbon:Button Label="Menu 2" Command="Paste"/>

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

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

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
            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()
            Return GetMenuItems()
        End Get
    End Property

End Class

Comments (2)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
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

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.

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.