Skip to content

Commit e6ed4e1

Browse files
authored
Merge pull request #2826 from MahApps/develop
Merging content for 1.4.2 develop to master
2 parents 6c1dd3d + 97af851 commit e6ed4e1

28 files changed

+406
-136
lines changed

docs/release-notes/1.4.2.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 1.4.2 Notes
2+
3+
## Changes / Fixes
4+
5+
- [#2814](https://github.com/MahApps/MahApps.Metro/pull/2814) Correct display of media buttons in `HotKeyBox` (thx @thoemmi)
6+
- [7fcc6b7](https://github.com/MahApps/MahApps.Metro/commit/7fcc6b770c77f483eb038705b252cfa7624a343f) Fix breaking changes for obsolete properties `ButtonHelper.PreserveTextCase`, `ButtonHelper.CornerRadius` and `ControlsHelper.ButtonWidth`
7+
- [a1d199d](https://github.com/MahApps/MahApps.Metro/commit/a1d199dd599fa9f46838d6449599b36c7035f76e) Fix binding to Content of HamburgerMenu
8+
- [#2799](https://github.com/MahApps/MahApps.Metro/pull/2799) DateTimePicker SelectedDate issue (thx @xxMUROxx)
9+
+ Fix issue where `SelectedDate` is set to the `DisplayDate` if the `SelectedDate` is `DateTime.MinValue`. This issue appears when binding to a property of DateTime and the date is `DateTime.MinValue`.
10+
- Z-Order was wrong if `MetroWindow` is ignoring the Taskbar and maximized. This fix and the main Taskbar z-Order issue only happens with Windows 10 anniversary update 1607. Hopefully fixed in the future. [#2780](https://github.com/MahApps/MahApps.Metro/issues/2780)
11+
- Use internal GetPhysicalCursorPos instead GetCursorPos (tested with remote desktop and different DPI) [#2748](https://github.com/MahApps/MahApps.Metro/issues/2748)
12+
13+
## Closed Issues
14+
15+
- [#2585](https://github.com/MahApps/MahApps.Metro/issues/2585) HotKeyBox gives wrong names to multimedia buttons
16+
- [#2817](https://github.com/MahApps/MahApps.Metro/issues/2817) TransitioningContentControl's TransitionCompleted event fires twice
17+
- [#2804](https://github.com/MahApps/MahApps.Metro/issues/2804) TransitionsEnabled=false NullpointerException
18+
- [#2823](https://github.com/MahApps/MahApps.Metro/issues/2823) Issue with ClearTextButton on TextBox
19+
- [#2815](https://github.com/MahApps/MahApps.Metro/issues/2815) Layout issue with TabControl, TabStripPlacement Left, TabControlHelper.IsUnderlined="True"
20+
- [#2770](https://github.com/MahApps/MahApps.Metro/issues/2770) Increase Win10 ToggleSwitch Default Margins
21+
- [#2780](https://github.com/MahApps/MahApps.Metro/issues/2780) External Dialogs not visible with MainWindow set to IgnoreTaskbarOnMaximize
22+
- [#2748](https://github.com/MahApps/MahApps.Metro/issues/2748) Access Denied

src/MahApps.Metro.Build/MahApps.Metro.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
33
<metadata>
44
<id>MahApps.Metro</id>
5-
<version>1.4.1.0</version>
5+
<version>1.4.2.0</version>
66
<title>MahApps.Metro</title>
77
<authors>Jan Karger, Dennis Daume, Brendan Forster, Paul Jenkins, Jake Ginnivan, Alex Mitchell</authors>
88
<owners>punker76,shiftkey,aeoth,jakeginnivan</owners>

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
Margin="20"
5656
Foreground="White"
5757
HamburgerWidth="48"
58+
Content="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay, Path=SelectedItem}"
5859
ItemClick="HamburgerMenu_OnItemClick"
5960
ItemTemplate="{StaticResource HamburgerMenuImageItem}"
6061
OptionsItemClick="HamburgerMenu_OnOptionsItemClick"

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ public HamburgerMenuSample()
1313

1414
private void HamburgerMenu_OnItemClick(object sender, ItemClickEventArgs e)
1515
{
16-
HamburgerMenuControl.Content = e.ClickedItem;
16+
// instead using binding Content="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay, Path=SelectedItem}"
17+
// we can do this
18+
//HamburgerMenuControl.Content = e.ClickedItem;
19+
20+
// close the menu if a item was selected
21+
if (this.HamburgerMenuControl.IsPaneOpen)
22+
{
23+
this.HamburgerMenuControl.IsPaneOpen = false;
24+
}
1725
}
1826

1927
private async void HamburgerMenu_OnOptionsItemClick(object sender, ItemClickEventArgs e)

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/TabControlExamples.xaml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,24 @@
104104
<Grid.Resources>
105105
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
106106
</Grid.Resources>
107-
<TabControl Height="100"
107+
<TabControl Height="200"
108108
Margin="0, 10, 0, 0"
109+
Controls:TabControlHelper.IsUnderlined="True"
109110
TabStripPlacement="Left">
110-
<TabItem Header="LeftItem0">
111-
<TextBlock FontSize="30" Text="This is left content 0" />
111+
<TabItem Header="LeftItem 0">
112+
<TextBlock FontSize="24" Text="This is left content 0" />
112113
</TabItem>
113-
<TabItem Header="LeftItem1">
114-
<TextBlock FontSize="30" Text="This is left content 1" />
114+
<TabItem Header="LeftItem 1 Header">
115+
<TextBlock FontSize="24" Text="This is left content 1" />
115116
</TabItem>
116-
<TabItem Header="LeftItem2">
117-
<TextBlock FontSize="30" Text="This is left content 2" />
117+
<TabItem Header="LeftItem 2 Text">
118+
<TextBlock FontSize="24" Text="This is left content 2" />
118119
</TabItem>
119-
<TabItem Header="LeftItem3">
120-
<TextBlock FontSize="30" Text="This is left content 3" />
120+
<TabItem Header="LeftItem 3">
121+
<TextBlock FontSize="24" Text="This is left content 3" />
121122
</TabItem>
122-
<TabItem Header="LeftItem4">
123-
<TextBlock FontSize="30" Text="This is left content 4" />
123+
<TabItem Header="LeftItem 4">
124+
<TextBlock FontSize="24" Text="This is left content 4" />
124125
</TabItem>
125126
</TabControl>
126127
</Grid>
@@ -274,6 +275,30 @@
274275
<TextBlock FontSize="24" Text="The size of close button will be changed proportionately considering its header size." />
275276
</Controls:MetroTabItem>
276277
</Controls:MetroTabControl>
278+
279+
<Label Margin="0, 5, 0, 0"
280+
Content="MetroTabControl _left style"
281+
Style="{DynamicResource DescriptionHeaderStyle}" />
282+
<Controls:MetroTabControl Height="220"
283+
Margin="0, 10, 0, 0"
284+
Controls:TabControlHelper.IsUnderlined="True"
285+
TabStripPlacement="Left">
286+
<Controls:MetroTabItem Header="LeftItem 0">
287+
<TextBlock FontSize="24" Text="This is left content 0" />
288+
</Controls:MetroTabItem>
289+
<Controls:MetroTabItem Header="LeftItem 1 Header">
290+
<TextBlock FontSize="24" Text="This is left content 1" />
291+
</Controls:MetroTabItem>
292+
<Controls:MetroTabItem Header="LeftItem 2 Text">
293+
<TextBlock FontSize="24" Text="This is left content 2" />
294+
</Controls:MetroTabItem>
295+
<Controls:MetroTabItem Header="LeftItem 3" CloseButtonEnabled="True">
296+
<TextBlock FontSize="24" Text="This is left content 3" />
297+
</Controls:MetroTabItem>
298+
<Controls:MetroTabItem Header="LeftItem 4">
299+
<TextBlock FontSize="24" Text="This is left content 4" />
300+
</Controls:MetroTabItem>
301+
</Controls:MetroTabControl>
277302
</StackPanel>
278303
</Expander>
279304
</StackPanel>

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/TextExamples.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@
346346
Margin="{StaticResource ColumnMargin}">
347347
<Label Style="{DynamicResource DescriptionHeaderStyle}" Content="HotKeyBox" />
348348
<Controls:HotKeyBox Margin="{StaticResource ControlMargin}"
349-
Controls:ControlsHelper.ContentCharacterCasing="Upper"
350349
AreModifierKeysRequired="{Binding ElementName=ModifierKeysRequired, Path=IsChecked}"
351350
HotKey="{Binding HotKey, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"
352351
Watermark="Enter hot key" />

src/MahApps.Metro/MahApps.Metro.Shared/Behaviours/BorderlessWindowBehavior.cs

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ protected override void OnAttached()
122122
this.AssociatedObject.Deactivated += (sender, args) => { topmostHack(); };
123123

124124
this.AssociatedObject.Loaded += this.AssociatedObject_Loaded;
125-
this.AssociatedObject.Unloaded += this.AssociatedObject_Unloaded;
125+
this.AssociatedObject.Unloaded += this.AssociatedObjectUnloaded;
126+
this.AssociatedObject.Closed += this.AssociatedObjectClosed;
126127
this.AssociatedObject.SourceInitialized += this.AssociatedObject_SourceInitialized;
127128
this.AssociatedObject.StateChanged += this.OnAssociatedObjectHandleMaximize;
128129

@@ -229,6 +230,11 @@ private void Cleanup()
229230
{
230231
this.isCleanedUp = true;
231232

233+
if (GetHandleTaskbar(this.AssociatedObject) && this.isWindwos10OrHigher)
234+
{
235+
this.DeactivateTaskbarFix();
236+
}
237+
232238
// clean up events
233239
if (this.AssociatedObject is MetroWindow)
234240
{
@@ -238,7 +244,8 @@ private void Cleanup()
238244
.RemoveValueChanged(this.AssociatedObject, this.UseNoneWindowStylePropertyChangedCallback);
239245
}
240246
this.AssociatedObject.Loaded -= this.AssociatedObject_Loaded;
241-
this.AssociatedObject.Unloaded -= this.AssociatedObject_Unloaded;
247+
this.AssociatedObject.Unloaded -= this.AssociatedObjectUnloaded;
248+
this.AssociatedObject.Closed -= this.AssociatedObjectClosed;
242249
this.AssociatedObject.SourceInitialized -= this.AssociatedObject_SourceInitialized;
243250
this.AssociatedObject.StateChanged -= this.OnAssociatedObjectHandleMaximize;
244251
if (this.hwndSource != null)
@@ -255,7 +262,12 @@ protected override void OnDetaching()
255262
base.OnDetaching();
256263
}
257264

258-
private void AssociatedObject_Unloaded(object sender, RoutedEventArgs e)
265+
private void AssociatedObjectUnloaded(object sender, RoutedEventArgs e)
266+
{
267+
this.Cleanup();
268+
}
269+
270+
private void AssociatedObjectClosed(object sender, EventArgs e)
259271
{
260272
this.Cleanup();
261273
}
@@ -315,34 +327,17 @@ private void HandleMaximize()
315327
var monitorInfo = new MONITORINFO();
316328
UnsafeNativeMethods.GetMonitorInfo(monitor, monitorInfo);
317329

318-
if (ignoreTaskBar)
330+
var x = monitorInfo.rcMonitor.left;
331+
var y = monitorInfo.rcMonitor.top;
332+
var cx = Math.Abs(monitorInfo.rcMonitor.right - x);
333+
var cy = Math.Abs(monitorInfo.rcMonitor.bottom - y);
334+
335+
if (ignoreTaskBar && this.isWindwos10OrHigher)
319336
{
320-
var x = monitorInfo.rcMonitor.left;
321-
var y = monitorInfo.rcMonitor.top;
322-
var cx = Math.Abs(monitorInfo.rcMonitor.right - x);
323-
var cy = Math.Abs(monitorInfo.rcMonitor.bottom - y);
324-
325-
var trayHWND = Standard.NativeMethods.FindWindow("Shell_TrayWnd", null);
326-
if (this.isWindwos10OrHigher && trayHWND != IntPtr.Zero)
327-
{
328-
UnsafeNativeMethods.SetWindowPos(this.handle, trayHWND, x, y, cx, cy, 0x0040);
329-
Standard.NativeMethods.ShowWindow(this.handle, Standard.SW.HIDE);
330-
Standard.NativeMethods.ShowWindow(this.handle, Standard.SW.SHOW);
331-
}
332-
else
333-
{
334-
UnsafeNativeMethods.SetWindowPos(this.handle, new IntPtr(-2), x, y, cx, cy, 0x0040);
335-
}
337+
this.ActivateTaskbarFix();
336338
}
337-
else
338-
{
339-
var x = monitorInfo.rcWork.left;
340-
var y = monitorInfo.rcWork.top;
341-
var cx = Math.Abs(monitorInfo.rcWork.right - x);
342-
var cy = Math.Abs(monitorInfo.rcWork.bottom - y);
343339

344-
UnsafeNativeMethods.SetWindowPos(this.handle, new IntPtr(-2), x, y, cx, cy, 0x0040);
345-
}
340+
UnsafeNativeMethods.SetWindowPos(this.handle, new IntPtr(-2), x, y, cx, cy, 0x0040);
346341
}
347342
}
348343
}
@@ -360,23 +355,9 @@ private void HandleMaximize()
360355

361356
// #2694 make sure the window is not on top after restoring window
362357
// this issue was introduced after fixing the windows 10 bug with the taskbar and a maximized window that ignores the taskbar
363-
RECT rect;
364-
if (UnsafeNativeMethods.GetWindowRect(this.handle, out rect))
358+
if (GetHandleTaskbar(this.AssociatedObject) && this.isWindwos10OrHigher)
365359
{
366-
var left = rect.left;
367-
var top = rect.top;
368-
var width = rect.Width;
369-
var height = rect.Height;
370-
371-
// #2780 Don't blindly set the Z-Order to HWWND_NOTOPMOST. If this window has an owner, set
372-
// the Z-Order to be after the owner. This keeps external dialogs appearing correctly above
373-
// their owner window even when owner window is maximized and ignoring taskbar.
374-
IntPtr hwndInsAfter = Constants.HWND_NOTOPMOST;
375-
if (this.AssociatedObject.Owner != null)
376-
{
377-
hwndInsAfter = new WindowInteropHelper(this.AssociatedObject.Owner).Handle;
378-
}
379-
UnsafeNativeMethods.SetWindowPos(this.handle, hwndInsAfter, left, top, width, height, 0x0040);
360+
this.DeactivateTaskbarFix();
380361
}
381362
}
382363

@@ -401,6 +382,46 @@ private void HandleMaximize()
401382
this.topMostChangeNotifier.RaiseValueChanged = raiseValueChanged;
402383
}
403384

385+
private void ActivateTaskbarFix()
386+
{
387+
var trayWndHandle = Standard.NativeMethods.FindWindow("Shell_TrayWnd", null);
388+
if (trayWndHandle != IntPtr.Zero)
389+
{
390+
SetHandleTaskbar(this.AssociatedObject, true);
391+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_BOTTOM, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
392+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_TOP, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
393+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_NOTOPMOST, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
394+
}
395+
}
396+
397+
private void DeactivateTaskbarFix()
398+
{
399+
var trayWndHandle = Standard.NativeMethods.FindWindow("Shell_TrayWnd", null);
400+
if (trayWndHandle != IntPtr.Zero)
401+
{
402+
SetHandleTaskbar(this.AssociatedObject, false);
403+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_BOTTOM, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
404+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_TOP, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
405+
UnsafeNativeMethods.SetWindowPos(trayWndHandle, Constants.HWND_TOPMOST, 0, 0, 0, 0, Constants.TOPMOST_FLAGS);
406+
}
407+
}
408+
409+
private static readonly DependencyProperty HandleTaskbarProperty
410+
= DependencyProperty.RegisterAttached(
411+
"HandleTaskbar",
412+
typeof(bool),
413+
typeof(BorderlessWindowBehavior), new FrameworkPropertyMetadata(false));
414+
415+
private static bool GetHandleTaskbar(UIElement element)
416+
{
417+
return (bool)element.GetValue(HandleTaskbarProperty);
418+
}
419+
420+
private static void SetHandleTaskbar(UIElement element, bool value)
421+
{
422+
element.SetValue(HandleTaskbarProperty, value);
423+
}
424+
404425
private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
405426
{
406427
this.handle = new WindowInteropHelper(this.AssociatedObject).Handle;

src/MahApps.Metro/MahApps.Metro.Shared/Controls/GlowWindow.xaml.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
299299
case WM.LBUTTONDOWN:
300300
if (this.ownerHandle != IntPtr.Zero && UnsafeNativeMethods.GetWindowRect(this.ownerHandle, out rect))
301301
{
302-
var pt = this.GetRelativeMousePosition();
302+
var pt = WinApiHelper.GetRelativeMousePosition(this.handle);
303303
NativeMethods.PostMessage(this.ownerHandle, (uint)WM.NCLBUTTONDOWN, (IntPtr)this.getHitTestValue(pt, rect), IntPtr.Zero);
304304
}
305305
break;
@@ -313,7 +313,7 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
313313
{
314314
if (this.ownerHandle != IntPtr.Zero && UnsafeNativeMethods.GetWindowRect(this.ownerHandle, out rect))
315315
{
316-
var pt = this.GetRelativeMousePosition();
316+
var pt = WinApiHelper.GetRelativeMousePosition(this.handle);
317317
cursor = this.getCursor(pt, rect);
318318
}
319319
}
@@ -325,16 +325,5 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
325325
}
326326
return IntPtr.Zero;
327327
}
328-
329-
private Point GetRelativeMousePosition()
330-
{
331-
if (this.handle == IntPtr.Zero)
332-
{
333-
return new Point();
334-
}
335-
var point = Standard.NativeMethods.GetCursorPos();
336-
Standard.NativeMethods.ScreenToClient(this.handle, ref point);
337-
return new Point(point.x, point.y);
338-
}
339328
}
340329
}

src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public override void OnApplyTemplate()
7070

7171
private void HamburgerMenu_Loaded(object sender, RoutedEventArgs e)
7272
{
73-
this.Content = _buttonsListView?.SelectedItem ?? _optionsListView?.SelectedItem;
73+
this.SetCurrentValue(ContentProperty, _buttonsListView?.SelectedItem ?? _optionsListView?.SelectedItem);
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)