style<Window>: icons for MaximizeWindow/RestoreWindow button

This commit is contained in:
leo 2021-06-22 10:09:50 +08:00
parent 787c1a02d5
commit 794394ef0c
9 changed files with 64 additions and 27 deletions

View file

@ -1,5 +1,6 @@
<controls:Window
x:Class="SourceGit.Views.Blame"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -35,7 +36,7 @@
<!-- Window Commands -->
<StackPanel Grid.Column="3" Orientation="Horizontal" WindowChrome.IsHitTestVisibleInChrome="True">
<controls:IconButton Click="Minimize" Width="28" Padding="8" Icon="{StaticResource Icon.Minimize}" HoverBackground="#40000000" Opacity="1"/>
<controls:IconButton Click="MaximizeOrRestore" Width="28" Padding="8" Icon="{StaticResource Icon.Maximize}" HoverBackground="#40000000" Opacity="1"/>
<ToggleButton Style="{StaticResource Style.ToggleButton.MaxOrRestore}" Width="28" IsChecked="{Binding ElementName=me, Path=IsMaximized}"/>
<controls:IconButton Click="Quit" Width="28" Padding="8" Icon="{StaticResource Icon.Close}" HoverBackground="Red" Opacity="1"/>
</StackPanel>
</Grid>

View file

@ -114,14 +114,6 @@ namespace SourceGit.Views {
SystemCommands.MinimizeWindow(this);
}
private void MaximizeOrRestore(object sender, RoutedEventArgs e) {
if (WindowState == WindowState.Normal) {
SystemCommands.MaximizeWindow(this);
} else {
SystemCommands.RestoreWindow(this);
}
}
private void Quit(object sender, RoutedEventArgs e) {
Close();
}

View file

@ -8,6 +8,17 @@ namespace SourceGit.Views.Controls {
/// </summary>
public class Window : System.Windows.Window {
public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(
"IsMaximized",
typeof(bool),
typeof(Window),
new PropertyMetadata(false, OnIsMaximizedChanged));
public bool IsMaximized {
get { return (bool)GetValue(IsMaximizedProperty); }
set { SetValue(IsMaximizedProperty, value); }
}
public Window() {
Background = FindResource("Brush.Window") as Brush;
BorderBrush = FindResource("Brush.WindowBorder") as Brush;
@ -29,13 +40,26 @@ namespace SourceGit.Views.Controls {
var content = Content as FrameworkElement;
if (WindowState == WindowState.Maximized) {
if (!IsMaximized) IsMaximized = true;
BorderThickness = new Thickness(0);
content.Margin = new Thickness((SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2);
} else {
if (IsMaximized) IsMaximized = false;
BorderThickness = new Thickness(1);
content.Margin = new Thickness(0);
}
};
}
private static void OnIsMaximizedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
Window w = d as Window;
if (w != null) {
if (w.IsMaximized) {
SystemCommands.MaximizeWindow(w);
} else {
SystemCommands.RestoreWindow(w);
}
}
}
}
}

View file

@ -1,5 +1,6 @@
<controls:Window
x:Class="SourceGit.Views.Histories"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -36,7 +37,7 @@
<!-- Window Commands -->
<StackPanel Grid.Column="3" Orientation="Horizontal" WindowChrome.IsHitTestVisibleInChrome="True">
<controls:IconButton Click="Minimize" Width="28" Padding="8" Icon="{StaticResource Icon.Minimize}" HoverBackground="#40000000" Opacity="1"/>
<controls:IconButton Click="MaximizeOrRestore" Width="28" Padding="8" Icon="{StaticResource Icon.Maximize}" HoverBackground="#40000000" Opacity="1"/>
<ToggleButton Style="{StaticResource Style.ToggleButton.MaxOrRestore}" Width="28" IsChecked="{Binding ElementName=me, Path=IsMaximized}"/>
<controls:IconButton Click="Quit" Width="28" Padding="8" Icon="{StaticResource Icon.Close}" HoverBackground="Red" Opacity="1"/>
</StackPanel>
</Grid>

View file

@ -36,14 +36,6 @@ namespace SourceGit.Views {
SystemCommands.MinimizeWindow(this);
}
private void MaximizeOrRestore(object sender, RoutedEventArgs e) {
if (WindowState == WindowState.Normal) {
SystemCommands.MaximizeWindow(this);
} else {
SystemCommands.RestoreWindow(this);
}
}
private void Quit(object sender, RoutedEventArgs e) {
Close();
}

View file

@ -43,7 +43,7 @@
<controls:IconButton Click="OpenPreference" Width="28" Padding="6" Icon="{StaticResource Icon.Preference}" ToolTip="{StaticResource Text.Launcher.Preference}"/>
<controls:IconButton Click="OpenAbout" Width="28" Padding="6" Icon="{StaticResource Icon.Help}" ToolTip="{StaticResource Text.Launcher.About}"/>
<controls:IconButton Click="Minimize" Width="28" Padding="8" Icon="{StaticResource Icon.Minimize}" HoverBackground="#40000000" Opacity="1"/>
<controls:IconButton Click="MaximizeOrRestore" Width="28" Padding="8" Icon="{StaticResource Icon.Maximize}" HoverBackground="#40000000" Opacity="1"/>
<ToggleButton Style="{StaticResource Style.ToggleButton.MaxOrRestore}" Width="28" IsChecked="{Binding ElementName=me, Path=IsMaximized}"/>
<controls:IconButton Click="Quit" Width="28" Padding="8" Icon="{StaticResource Icon.Close}" HoverBackground="Red" Opacity="1"/>
</StackPanel>
</Grid>

View file

@ -57,14 +57,6 @@ namespace SourceGit.Views {
SystemCommands.MinimizeWindow(this);
}
private void MaximizeOrRestore(object sender, RoutedEventArgs e) {
if (WindowState == WindowState.Normal) {
SystemCommands.MaximizeWindow(this);
} else {
SystemCommands.RestoreWindow(this);
}
}
private void Quit(object sender, RoutedEventArgs e) {
Application.Current.Shutdown();
}