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.
Thx.
Xaml :The VB code :
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>
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