|
|
@@ -2,19 +2,19 @@
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
using System;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Linq;
|
|
|
using System.Reactive.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Avalonia.Controls.Platform;
|
|
|
+using Avalonia.Data;
|
|
|
using Avalonia.Input;
|
|
|
+using Avalonia.Interactivity;
|
|
|
using Avalonia.Layout;
|
|
|
using Avalonia.Media;
|
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.Styling;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
using JetBrains.Annotations;
|
|
|
-using System.ComponentModel;
|
|
|
-using Avalonia.Interactivity;
|
|
|
|
|
|
namespace Avalonia.Controls
|
|
|
{
|
|
|
@@ -45,6 +45,27 @@ namespace Avalonia.Controls
|
|
|
WidthAndHeight = 3,
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Determines system decorations (title bar, border, etc) for a <see cref="Window"/>
|
|
|
+ /// </summary>
|
|
|
+ public enum SystemDecorations
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// No decorations
|
|
|
+ /// </summary>
|
|
|
+ None = 0,
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Window border without titlebar
|
|
|
+ /// </summary>
|
|
|
+ BorderOnly = 1,
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Fully decorated (default)
|
|
|
+ /// </summary>
|
|
|
+ Full = 2
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// A top-level window.
|
|
|
/// </summary>
|
|
|
@@ -59,8 +80,18 @@ namespace Avalonia.Controls
|
|
|
/// <summary>
|
|
|
/// Enables or disables system window decorations (title bar, buttons, etc)
|
|
|
/// </summary>
|
|
|
- public static readonly StyledProperty<bool> HasSystemDecorationsProperty =
|
|
|
- AvaloniaProperty.Register<Window, bool>(nameof(HasSystemDecorations), true);
|
|
|
+ [Obsolete("Use SystemDecorationsProperty instead")]
|
|
|
+ public static readonly DirectProperty<Window, bool> HasSystemDecorationsProperty =
|
|
|
+ AvaloniaProperty.RegisterDirect<Window, bool>(
|
|
|
+ nameof(HasSystemDecorations),
|
|
|
+ o => o.HasSystemDecorations,
|
|
|
+ (o, v) => o.HasSystemDecorations = v);
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Defines the <see cref="SystemDecorations"/> property.
|
|
|
+ /// </summary>
|
|
|
+ public static readonly StyledProperty<SystemDecorations> SystemDecorationsProperty =
|
|
|
+ AvaloniaProperty.Register<Window, SystemDecorations>(nameof(SystemDecorations), SystemDecorations.Full);
|
|
|
|
|
|
/// <summary>
|
|
|
/// Enables or disables the taskbar icon
|
|
|
@@ -124,9 +155,6 @@ namespace Avalonia.Controls
|
|
|
{
|
|
|
BackgroundProperty.OverrideDefaultValue(typeof(Window), Brushes.White);
|
|
|
TitleProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl?.SetTitle((string)e.NewValue));
|
|
|
- HasSystemDecorationsProperty.Changed.AddClassHandler<Window>(
|
|
|
- (s, e) => s.PlatformImpl?.SetSystemDecorations((bool)e.NewValue));
|
|
|
-
|
|
|
ShowInTaskbarProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.ShowTaskbarIcon((bool)e.NewValue));
|
|
|
|
|
|
IconProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl?.SetIcon(((WindowIcon)e.NewValue)?.PlatformImpl));
|
|
|
@@ -135,12 +163,11 @@ namespace Avalonia.Controls
|
|
|
|
|
|
WindowStateProperty.Changed.AddClassHandler<Window>(
|
|
|
(w, e) => { if (w.PlatformImpl != null) w.PlatformImpl.WindowState = (WindowState)e.NewValue; });
|
|
|
-
|
|
|
+
|
|
|
MinWidthProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size((double)e.NewValue, w.MinHeight), new Size(w.MaxWidth, w.MaxHeight)));
|
|
|
MinHeightProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, (double)e.NewValue), new Size(w.MaxWidth, w.MaxHeight)));
|
|
|
MaxWidthProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size((double)e.NewValue, w.MaxHeight)));
|
|
|
MaxHeightProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size(w.MaxWidth, (double)e.NewValue)));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -191,11 +218,30 @@ namespace Avalonia.Controls
|
|
|
/// <summary>
|
|
|
/// Enables or disables system window decorations (title bar, buttons, etc)
|
|
|
/// </summary>
|
|
|
- ///
|
|
|
+ [Obsolete("Use SystemDecorations instead")]
|
|
|
public bool HasSystemDecorations
|
|
|
{
|
|
|
- get { return GetValue(HasSystemDecorationsProperty); }
|
|
|
- set { SetValue(HasSystemDecorationsProperty, value); }
|
|
|
+ get => SystemDecorations == SystemDecorations.Full;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ var oldValue = HasSystemDecorations;
|
|
|
+
|
|
|
+ if (oldValue != value)
|
|
|
+ {
|
|
|
+ SystemDecorations = value ? SystemDecorations.Full : SystemDecorations.None;
|
|
|
+ RaisePropertyChanged(HasSystemDecorationsProperty, oldValue, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Sets the system decorations (title bar, border, etc)
|
|
|
+ /// </summary>
|
|
|
+ ///
|
|
|
+ public SystemDecorations SystemDecorations
|
|
|
+ {
|
|
|
+ get { return GetValue(SystemDecorationsProperty); }
|
|
|
+ set { SetValue(SystemDecorationsProperty, value); }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -584,5 +630,27 @@ namespace Avalonia.Controls
|
|
|
/// <see cref="Closing"/> event needs to be raised.
|
|
|
/// </remarks>
|
|
|
protected virtual void OnClosing(CancelEventArgs e) => Closing?.Invoke(this, e);
|
|
|
+
|
|
|
+ protected override void OnPropertyChanged<T>(
|
|
|
+ AvaloniaProperty<T> property,
|
|
|
+ Optional<T> oldValue,
|
|
|
+ BindingValue<T> newValue,
|
|
|
+ BindingPriority priority)
|
|
|
+ {
|
|
|
+ if (property == SystemDecorationsProperty)
|
|
|
+ {
|
|
|
+ var typedNewValue = newValue.GetValueOrDefault<SystemDecorations>();
|
|
|
+
|
|
|
+ PlatformImpl?.SetSystemDecorations(typedNewValue);
|
|
|
+
|
|
|
+ var o = oldValue.GetValueOrDefault<SystemDecorations>() == SystemDecorations.Full;
|
|
|
+ var n = typedNewValue == SystemDecorations.Full;
|
|
|
+
|
|
|
+ if (o != n)
|
|
|
+ {
|
|
|
+ RaisePropertyChanged(HasSystemDecorationsProperty, o, n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|