mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-23 01:38:40 +08:00
Fix fullscreen bug
This commit is contained in:
@@ -14,16 +14,16 @@ public class CaptionButtonGroup : TemplatedControl
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<bool> IsFullScreenEnabledProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsFullScreenEnabled), true);
|
||||
|
||||
Window.IsFullScreenEnabledProperty.AddOwner<CaptionButtonGroup>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsMaximizeEnabledProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsMaximizeEnabled), defaultValue: true);
|
||||
|
||||
Window.IsMaximizeEnabledProperty.AddOwner<CaptionButtonGroup>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsMinimizeEnabledProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsMinimizeEnabled), defaultValue: true);
|
||||
|
||||
Window.IsMinimizeEnabledProperty.AddOwner<CaptionButtonGroup>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsPinEnabledProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsPinEnabled), true);
|
||||
Window.IsPinEnabledProperty.AddOwner<CaptionButtonGroup>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsWindowActiveProperty =
|
||||
TitleBar.IsWindowActiveProperty.AddOwner<CaptionButtonGroup>();
|
||||
@@ -143,7 +143,11 @@ public class CaptionButtonGroup : TemplatedControl
|
||||
return;
|
||||
}
|
||||
|
||||
HostWindow = hostWindow;
|
||||
HostWindow = hostWindow;
|
||||
this[!IsFullScreenEnabledProperty] = hostWindow[!IsFullScreenEnabledProperty];
|
||||
this[!IsPinEnabledProperty] = hostWindow[!IsPinEnabledProperty];
|
||||
this[!IsMaximizeEnabledProperty] = hostWindow[!IsMaximizeEnabledProperty];
|
||||
this[!IsMinimizeEnabledProperty] = hostWindow[!IsMinimizeEnabledProperty];
|
||||
_disposables = new CompositeDisposable
|
||||
{
|
||||
HostWindow.GetObservable(Window.WindowStateProperty)
|
||||
@@ -229,15 +233,11 @@ public class CaptionButtonGroup : TemplatedControl
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isWindowFullScreen)
|
||||
if (!IsWindowFullScreen)
|
||||
{
|
||||
_originWindowState = HostWindow.WindowState;
|
||||
}
|
||||
else
|
||||
{
|
||||
HostWindow.WindowState = WindowState.FullScreen;
|
||||
}
|
||||
HostWindow.WindowState = _isWindowFullScreen
|
||||
HostWindow.WindowState = IsWindowFullScreen
|
||||
? _originWindowState ?? WindowState.Normal
|
||||
: WindowState.FullScreen;
|
||||
IsWindowFullScreen = HostWindow.WindowState == WindowState.FullScreen;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace AtomUI.Controls.Converters;
|
||||
|
||||
internal class FullScreenButtonVisibleConverter : IMultiValueConverter
|
||||
{
|
||||
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Count != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var isFullScreenEnabled = values[0] as bool?;
|
||||
var isMaximized = values[1] as bool?;
|
||||
return isFullScreenEnabled == true && isMaximized != true;
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,27 @@
|
||||
x:ClassModifier="internal">
|
||||
<converters:MaximizeButtonVisibleConverter x:Key="MaximizeButtonVisibleConverter" />
|
||||
<converters:MinimizeButtonVisibleConverter x:Key="MinimizeButtonVisibleConverter" />
|
||||
<converters:FullScreenButtonVisibleConverter x:Key="FullScreenButtonVisibleConverter"/>
|
||||
<ControlTheme x:Key="{x:Type atom:CaptionButtonGroup}" TargetType="atom:CaptionButtonGroup">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<StackPanel Orientation="Horizontal" Name="RootLayout">
|
||||
<atom:CaptionButton
|
||||
Name="{x:Static atom:CaptionButtonGroupThemeConstants.FullScreenButtonPart}"
|
||||
IsVisible="{TemplateBinding IsFullScreenEnabled}"
|
||||
IsEnabled="{TemplateBinding IsFullScreenEnabled}"
|
||||
IsWindowActive="{TemplateBinding IsWindowActive}"
|
||||
NormalIcon="{atom:IconProvider Kind=FullscreenOutlined}"
|
||||
CheckedIcon="{atom:IconProvider Kind=FullscreenExitOutlined}"
|
||||
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
|
||||
IsChecked="{TemplateBinding IsWindowFullScreen}" />
|
||||
IsChecked="{TemplateBinding IsWindowFullScreen}">
|
||||
<atom:CaptionButton.IsVisible>
|
||||
<MultiBinding
|
||||
Converter="{StaticResource FullScreenButtonVisibleConverter}">
|
||||
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsFullScreenEnabled" />
|
||||
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsWindowMaximized" />
|
||||
</MultiBinding>
|
||||
</atom:CaptionButton.IsVisible>
|
||||
</atom:CaptionButton>
|
||||
<atom:CaptionButton
|
||||
Name="{x:Static atom:CaptionButtonGroupThemeConstants.PinButtonPart}"
|
||||
IsVisible="{TemplateBinding IsPinEnabled}"
|
||||
|
||||
@@ -16,7 +16,7 @@ using AvaloniaWindow = Avalonia.Controls.Window;
|
||||
|
||||
public class Window : AvaloniaWindow, IDisposable
|
||||
{
|
||||
#region 公共属性
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<bool> IsTitleBarVisibleProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsTitleBarVisible), defaultValue: true);
|
||||
@@ -40,16 +40,16 @@ public class Window : AvaloniaWindow, IDisposable
|
||||
TitleBar.LogoProperty.AddOwner<Window>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsFullScreenEnabledProperty =
|
||||
CaptionButtonGroup.IsFullScreenEnabledProperty.AddOwner<Window>();
|
||||
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsFullScreenEnabled));
|
||||
|
||||
public static readonly StyledProperty<bool> IsMaximizeEnabledProperty =
|
||||
CaptionButtonGroup.IsMaximizeEnabledProperty.AddOwner<Window>();
|
||||
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsMaximizeEnabled), defaultValue: true);
|
||||
|
||||
public static readonly StyledProperty<bool> IsMinimizeEnabledProperty =
|
||||
CaptionButtonGroup.IsMinimizeEnabledProperty.AddOwner<Window>();
|
||||
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsMinimizeEnabled), defaultValue: true);
|
||||
|
||||
public static readonly StyledProperty<bool> IsPinEnabledProperty =
|
||||
CaptionButtonGroup.IsPinEnabledProperty.AddOwner<Window>();
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsPinEnabled));
|
||||
|
||||
public static readonly StyledProperty<bool> IsMoveEnabledProperty =
|
||||
AvaloniaProperty.Register<Window, bool>(nameof(IsMoveEnabled), defaultValue: true);
|
||||
|
||||
Reference in New Issue
Block a user