Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into punker76-Hamburger…
Browse files Browse the repository at this point in the history
…Menu-Content-Binding-fix
  • Loading branch information
punker76 committed Jan 27, 2017
2 parents e57527d + 7fcc6b7 commit ae0f648
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ public static class ButtonHelper
new FrameworkPropertyMetadata(
false,
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
PreserveTextCasePropertyChangedCallback));

private static void PreserveTextCasePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is bool)
{
var button = dependencyObject as Button;
if (button != null)
{
ControlsHelper.SetContentCharacterCasing(button, (bool)e.NewValue ? CharacterCasing.Normal : CharacterCasing.Upper);
}
}
}
(o, e) =>
{
var button = o as ButtonBase;
if (button != null && e.NewValue is bool)
{
ControlsHelper.SetContentCharacterCasing(button, (bool)e.NewValue ? CharacterCasing.Normal : CharacterCasing.Upper);
}
}));

/// <summary>
/// Overrides the text case behavior for certain buttons.
Expand All @@ -52,9 +47,17 @@ public static void SetPreserveTextCase(UIElement element, bool value)
public static readonly DependencyProperty CornerRadiusProperty
= DependencyProperty.RegisterAttached("CornerRadius", typeof(CornerRadius), typeof(ButtonHelper),
new FrameworkPropertyMetadata(
new CornerRadius(),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));

new CornerRadius(-1), // this is not valid, but this property is obsolete, set this to -1 to get the fired property changed callback
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
(o, e) =>
{
var element = o as UIElement;
if (element != null && e.OldValue != e.NewValue && e.NewValue is CornerRadius)
{
ControlsHelper.SetCornerRadius(element, (CornerRadius)e.NewValue);
}
}));

/// <summary>
/// The CornerRadius property allows users to control the roundness of the button corners independently by
/// setting a radius value for each corner. Radius values that are too large are scaled so that they
Expand All @@ -66,12 +69,12 @@ public static readonly DependencyProperty CornerRadiusProperty
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
public static CornerRadius GetCornerRadius(UIElement element)
{
return ControlsHelper.GetCornerRadius(element);
return (CornerRadius)element.GetValue(CornerRadiusProperty);
}

public static void SetCornerRadius(UIElement element, CornerRadius value)
{
ControlsHelper.SetCornerRadius(element, value);
element.SetValue(CornerRadiusProperty, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,27 @@ public static void SetHeaderMargin(UIElement element, Thickness value)
[Obsolete(@"This property will be deleted in the next release. You should use TextBoxHelper.ButtonWidth instead.")]
public static readonly DependencyProperty ButtonWidthProperty =
DependencyProperty.RegisterAttached("ButtonWidth", typeof(double), typeof(ControlsHelper),
new FrameworkPropertyMetadata(22d, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits));
new FrameworkPropertyMetadata(
22d,
FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits,
(o, e) =>
{
var element = o as UIElement;
if (element != null && e.OldValue != e.NewValue && e.NewValue is double)
{
TextBoxHelper.SetButtonWidth(element, (double)e.NewValue);
}
}));

[Category(AppName.MahApps)]
public static double GetButtonWidth(DependencyObject obj)
{
return TextBoxHelper.GetButtonWidth(obj);
return (double)obj.GetValue(ButtonWidthProperty);
}

public static void SetButtonWidth(DependencyObject obj, double value)
{
TextBoxHelper.SetButtonWidth(obj, value);
obj.SetValue(ButtonWidthProperty, value);
}

public static readonly DependencyProperty FocusBorderBrushProperty = DependencyProperty.RegisterAttached("FocusBorderBrush", typeof(Brush), typeof(ControlsHelper), new FrameworkPropertyMetadata(Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
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
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,12 @@ public void ReloadTransition()

private void OnTransitionCompleted(object sender, EventArgs e)
{
var clockGroup = sender as ClockGroup;
this.AbortTransition();
this.TransitionCompleted?.Invoke(this, new RoutedEventArgs());
if (clockGroup == null || clockGroup.CurrentState == ClockState.Stopped)
{
this.TransitionCompleted?.Invoke(this, new RoutedEventArgs());
}
}

public void AbortTransition()
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 ae0f648

Please sign in to comment.