Skip to content

Commit 1b32a21

Browse files
committed
Fix maximized behavior
1 parent f683e4d commit 1b32a21

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

RoundedScreen/MainWindow.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:RoundedScreen"
77
mc:Ignorable="d"
8-
Title="RoundedScreen" Height="450" Width="800" Topmost="True" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowState="Maximized" ShowInTaskbar="False" Focusable="False" IsTabStop="False" Closing="WndRoundedScreen_Closing" WindowStyle="None" AllowsTransparency="True">
8+
Title="RoundedScreen" Loaded="WndRoundedScreen_Loaded" Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}" Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" Topmost="True" ResizeMode="NoResize" WindowStartupLocation="Manual" ShowInTaskbar="False" Focusable="False" IsTabStop="False" Closing="WndRoundedScreen_Closing" WindowStyle="None" AllowsTransparency="True" LostFocus="WndRoundedScreen_LostFocus" Left="0" Top="0">
99
<Window.Resources>
1010
<Storyboard x:Key="Opening">
1111
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
@@ -24,8 +24,8 @@
2424
Opacity="0.0" />
2525
</Window.Background>
2626
<Grid x:Name="grid">
27-
<Image x:Name="imgCornerTL" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="12" Source="pack://siteoforigin:,,,/Resources/Corner.png"/>
28-
<Image x:Name="imgCornerTR" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Top" Width="12" Source="pack://siteoforigin:,,,/Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
27+
<Image x:Name="imgCornerTL" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="16" Source="Resources/Corner.png"/>
28+
<Image x:Name="imgCornerTR" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Top" Width="16" Source="Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
2929
<Image.RenderTransform>
3030
<TransformGroup>
3131
<ScaleTransform/>
@@ -35,7 +35,7 @@
3535
</TransformGroup>
3636
</Image.RenderTransform>
3737
</Image>
38-
<Image x:Name="imgCornerBR" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Bottom" Width="12" Source="pack://siteoforigin:,,,/Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
38+
<Image x:Name="imgCornerBR" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Bottom" Width="16" Source="Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
3939
<Image.RenderTransform>
4040
<TransformGroup>
4141
<ScaleTransform/>
@@ -45,7 +45,7 @@
4545
</TransformGroup>
4646
</Image.RenderTransform>
4747
</Image>
48-
<Image x:Name="imgCornerBL" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Bottom" Width="12" Source="pack://siteoforigin:,,,/Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
48+
<Image x:Name="imgCornerBL" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Bottom" Width="16" Source="Resources/Corner.png" RenderTransformOrigin="0.5,0.5">
4949
<Image.RenderTransform>
5050
<TransformGroup>
5151
<ScaleTransform/>

RoundedScreen/MainWindow.xaml.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@
88

99
namespace RoundedScreen
1010
{
11-
public static class PreventTouchToMousePromotion
12-
{
13-
public static void Register(FrameworkElement root)
14-
{
15-
root.PreviewMouseDown += Evaluate;
16-
root.PreviewMouseMove += Evaluate;
17-
root.PreviewMouseUp += Evaluate;
18-
}
19-
20-
private static void Evaluate(object sender, MouseEventArgs e)
21-
{
22-
if (e.StylusDevice != null)
23-
{
24-
e.Handled = true;
25-
}
26-
}
27-
}
28-
2911
public partial class MainWindow : Window
3012
{
3113
public const int WS_EX_TRANSPARENT = 0x00000020;
@@ -40,7 +22,7 @@ public partial class MainWindow : Window
4022
public MainWindow()
4123
{
4224
InitializeComponent();
43-
SetStartup();
25+
this.SetStartup();
4426
}
4527

4628
private void SetStartup()
@@ -59,5 +41,22 @@ protected override void OnSourceInitialized(EventArgs e)
5941
}
6042

6143
private void WndRoundedScreen_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; }
44+
45+
private void WndRoundedScreen_LostFocus(object sender, RoutedEventArgs e)
46+
{
47+
this.Activate();
48+
this.Topmost = true;
49+
this.Topmost = false;
50+
this.Focus();
51+
}
52+
53+
private void WndRoundedScreen_Loaded(object sender, RoutedEventArgs e)
54+
{
55+
Point location = this.PointToScreen(new Point(0, 0));
56+
this.WindowStartupLocation = WindowStartupLocation.Manual;
57+
58+
this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
59+
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
60+
}
6261
}
6362
}

RoundedScreen/RoundedScreen.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@
9696
<None Include="App.config" />
9797
</ItemGroup>
9898
<ItemGroup>
99-
<None Include="Resources\Corner.png">
100-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
101-
</None>
99+
<Resource Include="Resources\Corner.png" />
102100
</ItemGroup>
103101
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
104102
</Project>

0 commit comments

Comments
 (0)