Skip to content

Commit b5621f8

Browse files
authored
Merge branch 'develop' into develop
2 parents 86b40f3 + fb5a713 commit b5621f8

File tree

15 files changed

+118
-134
lines changed

15 files changed

+118
-134
lines changed

LICENSE

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1-
Microsoft Public License (Ms-PL)
1+
MIT License (MIT)
2+
3+
Copyright (c) 2016 MahApps
4+
5+
Unless indicated otherwise on a per-file basis all source and documentation herein
6+
is licensed under the MIT license. Some included code is licensed under MS-PL which
7+
is compatible with the terms of MIT.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
27+
-----
28+
29+
Original code from RangeSlider (AvalonControlsLibrary), ToggleSwitch (Microsoft's Silverlight "Cosmopolitan"),
30+
Callisto (@timheuer), WindowChrome (@Microsoft, @joecastro) and TransitioningContentControl from the
31+
Silverlight Toolkit 5 are licensed under MS-PL which is compatible with the terms of MIT.
32+
33+
-----
34+
35+
Microsoft Public License (MS-PL)
236

337
This license governs use of the accompanying software. If you use the software, you
438
accept this license. If you do not accept the license, do not use the software.
@@ -19,4 +53,4 @@ A "contributor" is any person that distributes its contribution under this licen
1953
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
2054
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
2155
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
22-
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
56+
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

Licenses/avaloncontrolslibrary

Lines changed: 0 additions & 32 deletions
This file was deleted.

Licenses/callisto

Lines changed: 0 additions & 25 deletions
This file was deleted.

Licenses/silverlighttoolkit

Lines changed: 0 additions & 32 deletions
This file was deleted.

MahApps.Metro/Controls/MetroWindow.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class MetroWindow : Window
7575
public static readonly DependencyProperty WindowPlacementSettingsProperty = DependencyProperty.Register("WindowPlacementSettings", typeof(IWindowPlacementSettings), typeof(MetroWindow), new PropertyMetadata(null));
7676
public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(MetroWindow));
7777
public static readonly DependencyProperty IgnoreTaskbarOnMaximizeProperty = DependencyProperty.Register("IgnoreTaskbarOnMaximize", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
78-
public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register("Flyouts", typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null));
78+
public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register("Flyouts", typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
7979
public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register("WindowTransitionsEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
8080
public static readonly DependencyProperty MetroDialogOptionsProperty = DependencyProperty.Register("MetroDialogOptions", typeof(MetroDialogSettings), typeof(MetroWindow), new PropertyMetadata(new MetroDialogSettings()));
8181

@@ -89,9 +89,9 @@ public class MetroWindow : Window
8989
public static readonly DependencyProperty IconTemplateProperty = DependencyProperty.Register("IconTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));
9090
public static readonly DependencyProperty TitleTemplateProperty = DependencyProperty.Register("TitleTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));
9191

92-
public static readonly DependencyProperty LeftWindowCommandsProperty = DependencyProperty.Register("LeftWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null));
93-
public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register("RightWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null));
94-
public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register("WindowButtonCommands", typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null));
92+
public static readonly DependencyProperty LeftWindowCommandsProperty = DependencyProperty.Register("LeftWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
93+
public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register("RightWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
94+
public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register("WindowButtonCommands", typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
9595

9696
public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("LeftWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always));
9797
public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("RightWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always));
@@ -815,6 +815,7 @@ public void ResetStoredFocus()
815815
/// </summary>
816816
public MetroWindow()
817817
{
818+
DataContextChanged += MetroWindow_DataContextChanged;
818819
Loaded += this.MetroWindow_Loaded;
819820
}
820821

@@ -836,6 +837,14 @@ protected override void OnClosing(CancelEventArgs e)
836837
}
837838
#endif
838839

840+
private void MetroWindow_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
841+
{
842+
if (this.LeftWindowCommands != null) this.LeftWindowCommands.DataContext = this.DataContext;
843+
if (this.RightWindowCommands != null) this.RightWindowCommands.DataContext = this.DataContext;
844+
if (this.WindowButtonCommands != null) this.WindowButtonCommands.DataContext = this.DataContext;
845+
if (this.Flyouts != null) this.Flyouts.DataContext = this.DataContext;
846+
}
847+
839848
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
840849
{
841850
if (EnableDWMDropShadow)
@@ -957,6 +966,26 @@ private void FlyoutsPreviewMouseDown(object sender, MouseButtonEventArgs e)
957966
}
958967
}
959968

969+
970+
private static void UpdateLogicalChilds(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
971+
{
972+
var window = dependencyObject as MetroWindow;
973+
if (window == null)
974+
{
975+
return;
976+
}
977+
var oldChild = e.OldValue as FrameworkElement;
978+
if (oldChild != null)
979+
{
980+
window.RemoveLogicalChild(oldChild);
981+
}
982+
var newChild = e.NewValue as FrameworkElement;
983+
if (newChild != null)
984+
{
985+
window.AddLogicalChild(newChild);
986+
}
987+
}
988+
960989
static MetroWindow()
961990
{
962991
DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroWindow), new FrameworkPropertyMetadata(typeof(MetroWindow)));
@@ -966,6 +995,10 @@ public override void OnApplyTemplate()
966995
{
967996
base.OnApplyTemplate();
968997

998+
LeftWindowCommandsPresenter = GetTemplateChild(PART_LeftWindowCommands) as ContentPresenter;
999+
RightWindowCommandsPresenter = GetTemplateChild(PART_RightWindowCommands) as ContentPresenter;
1000+
WindowButtonCommandsPresenter = GetTemplateChild(PART_WindowButtonCommands) as ContentPresenter;
1001+
9691002
if (LeftWindowCommands == null)
9701003
LeftWindowCommands = new WindowCommands();
9711004
if (RightWindowCommands == null)
@@ -977,10 +1010,6 @@ public override void OnApplyTemplate()
9771010
RightWindowCommands.ParentWindow = this;
9781011
WindowButtonCommands.ParentWindow = this;
9791012

980-
LeftWindowCommandsPresenter = GetTemplateChild(PART_LeftWindowCommands) as ContentPresenter;
981-
RightWindowCommandsPresenter = GetTemplateChild(PART_RightWindowCommands) as ContentPresenter;
982-
WindowButtonCommandsPresenter = GetTemplateChild(PART_WindowButtonCommands) as ContentPresenter;
983-
9841013
overlayBox = GetTemplateChild(PART_OverlayBox) as Grid;
9851014
metroActiveDialogContainer = GetTemplateChild(PART_MetroActiveDialogContainer) as Grid;
9861015
metroInactiveDialogContainer = GetTemplateChild(PART_MetroInactiveDialogsContainer) as Grid;

MahApps.Metro/Controls/TreeHelper.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static DependencyObject GetParentObject(this DependencyObject child)
107107
{
108108
if (child == null) return null;
109109

110-
//handle content elements separately
110+
// handle content elements separately
111111
var contentElement = child as ContentElement;
112112
if (contentElement != null)
113113
{
@@ -118,16 +118,21 @@ public static DependencyObject GetParentObject(this DependencyObject child)
118118
return fce != null ? fce.Parent : null;
119119
}
120120

121-
//also try searching for parent in framework elements (such as DockPanel, etc)
121+
var childParent = VisualTreeHelper.GetParent(child);
122+
if (childParent != null)
123+
{
124+
return childParent;
125+
}
126+
127+
// also try searching for parent in framework elements (such as DockPanel, etc)
122128
var frameworkElement = child as FrameworkElement;
123129
if (frameworkElement != null)
124130
{
125131
DependencyObject parent = frameworkElement.Parent;
126132
if (parent != null) return parent;
127133
}
128134

129-
//if it's not a ContentElement/FrameworkElement, rely on VisualTreeHelper
130-
return VisualTreeHelper.GetParent(child);
135+
return null;
131136
}
132137

133138
/// <summary>

0 commit comments

Comments
 (0)