From 8acc7c6f157a396d12e1ed477aac65070de58597 Mon Sep 17 00:00:00 2001 From: Artyom Date: Mon, 19 Mar 2018 23:05:12 +0300 Subject: [PATCH 1/2] Remove dollar! Close https://github.com/AvaloniaUI/Avalonia/issues/1397 --- src/Avalonia.Base/Collections/AvaloniaDictionary.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs index b90dccf74e..84ac85d3db 100644 --- a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs +++ b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs @@ -117,7 +117,7 @@ namespace Avalonia.Collections _inner = new Dictionary(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count")); - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[]")); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item[]")); if (CollectionChanged != null) @@ -222,4 +222,4 @@ namespace Avalonia.Collections } } } -} \ No newline at end of file +} From a89f9486f17173c4f5392393b0b99afffbdb8a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Tue, 3 Apr 2018 00:23:32 +0100 Subject: [PATCH 2/2] Implemented correct behavior for Command.CanExecute on MenuItem. --- src/Avalonia.Controls/MenuItem.cs | 35 +++++++++++++++++++++++ src/Avalonia.Themes.Default/MenuItem.xaml | 4 +++ 2 files changed, 39 insertions(+) diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index dadd3b910b..96f6fb59b0 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -93,6 +93,7 @@ namespace Avalonia.Controls static MenuItem() { SelectableMixin.Attach(IsSelectedProperty); + CommandProperty.Changed.Subscribe(CommandChanged); FocusableProperty.OverrideDefaultValue(true); IconProperty.Changed.AddClassHandler(x => x.IconChanged); ItemsPanelProperty.OverrideDefaultValue(DefaultPanel); @@ -424,6 +425,40 @@ namespace Avalonia.Controls } } + /// + /// Called when the property changes. + /// + /// The event args. + private static void CommandChanged(AvaloniaPropertyChangedEventArgs e) + { + if (e.Sender is MenuItem menuItem) + { + if (e.OldValue is ICommand oldCommand) + { + oldCommand.CanExecuteChanged -= menuItem.CanExecuteChanged; + } + + if (e.NewValue is ICommand newCommand) + { + newCommand.CanExecuteChanged += menuItem.CanExecuteChanged; + } + + menuItem.CanExecuteChanged(menuItem, EventArgs.Empty); + } + } + + /// + /// Called when the event fires. + /// + /// The event sender. + /// The event args. + private void CanExecuteChanged(object sender, EventArgs e) + { + // HACK: Just set the IsEnabled property for the moment. This needs to be changed to + // use IsEnabledCore etc. but it will do for now. + IsEnabled = Command == null || Command.CanExecute(CommandParameter); + } + /// /// Called when the property changes. /// diff --git a/src/Avalonia.Themes.Default/MenuItem.xaml b/src/Avalonia.Themes.Default/MenuItem.xaml index 1cd9587297..66f226d2f6 100644 --- a/src/Avalonia.Themes.Default/MenuItem.xaml +++ b/src/Avalonia.Themes.Default/MenuItem.xaml @@ -133,4 +133,8 @@ + + \ No newline at end of file