diff options
author | Bret Johnson <bret.johnson@microsoft.com> | 2022-03-19 01:28:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 01:28:19 +0300 |
commit | 032fdb64d317c1e5dda96450a3649f6d92dae9af (patch) | |
tree | 5674627270b0d7dc093f582d0919dd22b11b090e | |
parent | 626060a19b286ac6d06f63efc31202b9e34b461b (diff) |
Use PreviewKeyDown for Ctrl+Space to show menu (#800)
* Use PreviewKeyDown for Ctrl+Space to show menu
Ctrl+Space is the keyboard short that can
be used to show the property editor menu
for a property (with options like Reset,
Convert to Local Value, etc.). Previously, that
was detected via a KeyBinding in XAML, which
worked for text boxes but not controls like
checkbox and button, which handle the
key down event themselves. Now we
use PreviewKeyDown instead, handling that
in C# code, to work for all control
types.
Fixes AB#1491229
-rw-r--r--[-rwxr-xr-x] | Xamarin.PropertyEditing.Windows/PropertyPresenter.cs | 19 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Windows/Themes/Resources.xaml | 5 |
2 files changed, 20 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing.Windows/PropertyPresenter.cs b/Xamarin.PropertyEditing.Windows/PropertyPresenter.cs index 4cf1813..72a009b 100755..100644 --- a/Xamarin.PropertyEditing.Windows/PropertyPresenter.cs +++ b/Xamarin.PropertyEditing.Windows/PropertyPresenter.cs @@ -6,6 +6,7 @@ using System.Windows.Automation; using System.Windows.Automation.Peers; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using System.Windows.Input; using System.Windows.Media; using Xamarin.PropertyEditing.ViewModels; @@ -112,6 +113,12 @@ namespace Xamarin.PropertyEditing.Windows this.variationRow = (RowDefinition) GetTemplateChild ("variationRow"); this.variationsList = GetTemplateChild ("variationsList") as ItemsControl; + + this.propertyButton = (PropertyButton) GetTemplateChild ("propertyButton"); + + this.propertyContainer = (Border) GetTemplateChild ("propertyContainer"); + // Since the template never changes, the handler only gets added once and there's no need to unsubscribe + this.propertyContainer.AddHandler (Border.PreviewKeyDownEvent, new KeyEventHandler (PropertyContainer_PreviewKeyDown)); } protected override AutomationPeer OnCreateAutomationPeer () @@ -155,10 +162,22 @@ namespace Xamarin.PropertyEditing.Windows } } + private void PropertyContainer_PreviewKeyDown (object sender, KeyEventArgs e) + { + var isModifierControl = Keyboard.Modifiers == ModifierKeys.Control; + + if (e.Key == Key.Space && isModifierControl) { + propertyButton.ShowMenu (); + e.Handled = true; + } + } + private PropertyViewModel pvm; private ButtonBase addButton, removeButton; private RowDefinition variationRow; private ItemsControl variationsList; + private Border propertyContainer; + private PropertyButton propertyButton; private void OnLoaded (object sender, RoutedEventArgs e) { diff --git a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml index 2b0938e..cafc4c0 100644 --- a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml +++ b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml @@ -1708,10 +1708,7 @@ <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:PropertyPresenter"> - <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> - <Border.InputBindings> - <KeyBinding Gesture="CTRL+Space" Command="{StaticResource InvokePropertyButtonCommand}" CommandParameter="{Binding ElementName=propertyButton,Mode=OneTime}" /> - </Border.InputBindings> + <Border x:Name="propertyContainer" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Name="delveColumn" Width="Auto" /> |