Skip to content

Commit

Permalink
Reduce size of ShellView if default size > screen size
Browse files Browse the repository at this point in the history
Fixes #84
  • Loading branch information
canton7 committed May 11, 2015
1 parent 828ca24 commit 393da0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SyncTrayzor/Pages/ShellView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:xaml="clr-namespace:SyncTrayzor.Xaml"
xmlns:l="clr-namespace:SyncTrayzor.Localization"
Height="700" Width="1100"
Height="1200" Width="1100"
Title="SyncTrayzor">
<i:Interaction.Behaviors>
<xaml:ActivateBehaviour Activated="{Binding WindowActivated}"/>
Expand Down
12 changes: 12 additions & 0 deletions src/SyncTrayzor/Xaml/WindowPlacementBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace SyncTrayzor.Xaml
{
public class WindowPlacementBehaviour : DetachingBehaviour<Window>
{
private const int taskbarHeight = 40; // Max height

public WindowPlacement Placement
{
get { return (WindowPlacement)GetValue(PlacementProperty); }
Expand All @@ -26,6 +28,8 @@ protected override void AttachHandlers()
{
this.AssociatedObject.SourceInitialized += this.SourceInitialized;
this.AssociatedObject.Closing += this.Closing;

this.SetDefaultSize();
}

protected override void DetachHandlers()
Expand All @@ -34,6 +38,14 @@ protected override void DetachHandlers()
this.AssociatedObject.Closing -= this.Closing;
}

private void SetDefaultSize()
{
// Beware, we may be duplicating functionality in NoSizeBelowScreenBehaviour

this.AssociatedObject.Height = Math.Min(this.AssociatedObject.Height, SystemParameters.VirtualScreenHeight - taskbarHeight);
this.AssociatedObject.Width = Math.Min(this.AssociatedObject.Width, SystemParameters.VirtualScreenWidth - taskbarHeight);
}

private void SourceInitialized(object sender, EventArgs e)
{
if (this.Placement == null)
Expand Down

0 comments on commit 393da0b

Please sign in to comment.