Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jit compiler limitation fix for #1919 #1971

Merged
merged 3 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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