Skip to content

Commit

Permalink
Merge pull request #1971 from MahApps/1919-JIT-Compiler-limitation-fix
Browse files Browse the repository at this point in the history
jit compiler limitation fix for #1919
  • Loading branch information
punker76 committed Jun 11, 2015
2 parents de3cbbf + 651ecfe commit 212fbe4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
8 changes: 8 additions & 0 deletions MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,18 @@ public override void OnApplyTemplate()
if (RightWindowCommands == null)
RightWindowCommands = new WindowCommands();

LeftWindowCommands.ParentWindow = this;
RightWindowCommands.ParentWindow = this;

LeftWindowCommandsPresenter = GetTemplateChild(PART_LeftWindowCommands) as ContentPresenter;
RightWindowCommandsPresenter = GetTemplateChild(PART_RightWindowCommands) as ContentPresenter;
WindowButtonCommands = GetTemplateChild(PART_WindowButtonCommands) as WindowButtonCommands;

if (WindowButtonCommands != null)
{
WindowButtonCommands.ParentWindow = this;
}

overlayBox = GetTemplateChild(PART_OverlayBox) as Grid;
metroDialogContainer = GetTemplateChild(PART_MetroDialogContainer) as Grid;
flyoutModal = (Rectangle) GetTemplateChild(PART_FlyoutModal);
Expand Down
48 changes: 31 additions & 17 deletions MahApps.Metro/Controls/WindowButtonCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ static WindowButtonCommands()
DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowButtonCommands), new FrameworkPropertyMetadata(typeof(WindowButtonCommands)));
}

public WindowButtonCommands()
{
this.Loaded += WindowButtonCommands_Loaded;
}

private void WindowButtonCommands_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= WindowButtonCommands_Loaded;
var parentWindow = this.ParentWindow;
if (null == parentWindow)
{
this.ParentWindow = this.TryFindParent<MetroWindow>();
}
}

private string GetCaption(int id)
{
if (user32 == null)
Expand All @@ -93,26 +108,22 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();

this.ParentWindow = this.TryFindParent<MetroWindow>();
if (this.ParentWindow != null)
close = Template.FindName("PART_Close", this) as Button;
if (close != null)
{
close = Template.FindName("PART_Close", this) as Button;
if (close != null)
{
close.Click += CloseClick;
}
close.Click += CloseClick;
}

max = Template.FindName("PART_Max", this) as Button;
if (max != null)
{
max.Click += MaximizeClick;
}
max = Template.FindName("PART_Max", this) as Button;
if (max != null)
{
max.Click += MaximizeClick;
}

min = Template.FindName("PART_Min", this) as Button;
if (min != null)
{
min.Click += MinimizeClick;
}
min = Template.FindName("PART_Min", this) as Button;
if (min != null)
{
min.Click += MinimizeClick;
}
}

Expand All @@ -127,11 +138,13 @@ protected void OnClosingWindow(ClosingWindowEventHandlerArgs args)

private void MinimizeClick(object sender, RoutedEventArgs e)
{
if (null == this.ParentWindow) return;
Microsoft.Windows.Shell.SystemCommands.MinimizeWindow(this.ParentWindow);
}

private void MaximizeClick(object sender, RoutedEventArgs e)
{
if (null == this.ParentWindow) return;
if (this.ParentWindow.WindowState == WindowState.Maximized)
{
Microsoft.Windows.Shell.SystemCommands.RestoreWindow(this.ParentWindow);
Expand All @@ -152,6 +165,7 @@ private void CloseClick(object sender, RoutedEventArgs e)
return;
}

if (null == this.ParentWindow) return;
this.ParentWindow.Close();
}

Expand Down
15 changes: 12 additions & 3 deletions MahApps.Metro/Controls/WindowCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ static WindowCommands()
DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowCommands), new FrameworkPropertyMetadata(typeof(WindowCommands)));
}

public override void OnApplyTemplate()
public WindowCommands()
{
base.OnApplyTemplate();
this.ParentWindow = this.TryFindParent<Window>();
this.Loaded += WindowCommands_Loaded;
}

private void WindowCommands_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= WindowCommands_Loaded;
var parentWindow = this.ParentWindow;
if (null == parentWindow)
{
this.ParentWindow = this.TryFindParent<Window>();
}
}

private Window _parentWindow;
Expand Down
12 changes: 12 additions & 0 deletions Mahapps.Metro.Tests/MetroWindowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public async Task MetroWindowSmokeTest()
await WindowHelpers.CreateInvisibleWindowAsync<MetroWindow>();
}

[Fact]
public async Task WindowCommandsShouldHaveTheParentWindow()
{
await TestHost.SwitchToAppThread();

var window = await WindowHelpers.CreateInvisibleWindowAsync<MetroWindow>();

Assert.Equal(window, window.LeftWindowCommands.ParentWindow);
Assert.Equal(window, window.RightWindowCommands.ParentWindow);
Assert.Equal(window, window.WindowButtonCommands.ParentWindow);
}

[Fact]
public async Task ShowsRightWindowCommandsOnTopByDefault()
{
Expand Down

0 comments on commit 212fbe4

Please sign in to comment.