Skip to content

Commit

Permalink
Merge branch 'develop' into 2817-TransitioningContentControl-Transiti…
Browse files Browse the repository at this point in the history
…onCompleted-fix
  • Loading branch information
punker76 committed Jan 27, 2017
2 parents 41fec83 + eb7cd4b commit 224c283
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@
Margin="{StaticResource ColumnMargin}">
<Label Style="{DynamicResource DescriptionHeaderStyle}" Content="HotKeyBox" />
<Controls:HotKeyBox Margin="{StaticResource ControlMargin}"
Controls:ControlsHelper.ContentCharacterCasing="Upper"
AreModifierKeysRequired="{Binding ElementName=ModifierKeysRequired, Path=IsChecked}"
HotKey="{Binding HotKey, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"
Watermark="Enter hot key" />
Expand Down
21 changes: 16 additions & 5 deletions src/MahApps.Metro/MahApps.Metro.Shared/Controls/HotKeyBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public class HotKey : IEquatable<HotKey>
private readonly Key _key;
private readonly ModifierKeys _modifierKeys;

public HotKey(Key key, ModifierKeys modifierKeys)
public HotKey(Key key, ModifierKeys modifierKeys = ModifierKeys.None)
{
_key = key;
_modifierKeys = modifierKeys;
Expand Down Expand Up @@ -255,12 +255,23 @@ public override string ToString()
}
if ((_modifierKeys & ModifierKeys.Windows) == ModifierKeys.Windows)
{
sb.Append("WINDOWS+");
sb.Append("Windows+");
}
sb.Append(GetLocalizedKeyStringUnsafe(KeyInterop.VirtualKeyFromKey(_key)).ToUpper());
sb.Append(GetLocalizedKeyString(_key));
return sb.ToString();
}

private static string GetLocalizedKeyString(Key key)
{
if (key >= Key.BrowserBack && key <= Key.LaunchApplication2)
{
return key.ToString();
}

var vkey = KeyInterop.VirtualKeyFromKey(key);
return GetLocalizedKeyStringUnsafe(vkey) ?? key.ToString();
}

private static string GetLocalizedKeyStringUnsafe(int key)
{
// strip any modifier keys
Expand All @@ -281,8 +292,8 @@ private static string GetLocalizedKeyStringUnsafe(int key)
scanCode |= 0x1000000;
}

UnsafeNativeMethods.GetKeyNameText((int)scanCode, sb, 256);
return sb.ToString();
var resultLength = UnsafeNativeMethods.GetKeyNameText((int)scanCode, sb, 256);
return resultLength > 0 ? sb.ToString() : null;
}

}
Expand Down
1 change: 1 addition & 0 deletions src/MahApps.Metro/MahApps.Metro/Themes/HotKeyBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Controls:ControlsHelper.FocusBorderBrush" Value="{DynamicResource TextBoxFocusBorderBrush}" />
<Setter Property="Controls:ControlsHelper.MouseOverBorderBrush" Value="{DynamicResource TextBoxMouseOverBorderBrush}" />
<Setter Property="Controls:ControlsHelper.ContentCharacterCasing" Value="Upper" />
<Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
<Setter Property="MinHeight" Value="26" />
Expand Down

0 comments on commit 224c283

Please sign in to comment.