Browse Source

insert managed chrome when extend client area is enabled and hint flag is set.

demo1
Dan Walmsley 6 years ago
parent
commit
1e798be784
  1. 1
      samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml
  2. 16
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
  3. 34
      src/Avalonia.Controls/Window.cs

1
samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml

@ -8,6 +8,7 @@
<CheckBox Content="Extend Client Area to Decorations" IsChecked="{Binding ExtendClientAreaEnabled}" />
<CheckBox Content="Titlebar" IsChecked="{Binding SystemTitleBarEnabled}" />
<CheckBox Content="System Chrome Buttons" IsChecked="{Binding SystemChromeButtonsEnabled}" />
<CheckBox Content="Managed Chrome Buttons" IsChecked="{Binding ManagedChromeButtonsEnabled}" />
<Slider Minimum="-1" Maximum="200" Value="{Binding TitleBarHeight}" />
<ComboBox x:Name="TransparencyLevels" SelectedIndex="{Binding TransparencyLevel}">
<ComboBoxItem>None</ComboBoxItem>

16
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@ -65,7 +65,7 @@ namespace ControlCatalog.ViewModels
WindowState.FullScreen,
};
this.WhenAnyValue(x => x.SystemChromeButtonsEnabled, x => x.SystemTitleBarEnabled)
this.WhenAnyValue(x => x.SystemChromeButtonsEnabled, x=>x.ManagedChromeButtonsEnabled, x => x.SystemTitleBarEnabled)
.Subscribe(x =>
{
ChromeHints = ExtendClientAreaChromeHints.NoChrome;
@ -76,6 +76,11 @@ namespace ControlCatalog.ViewModels
}
if(x.Item2)
{
ChromeHints |= ExtendClientAreaChromeHints.ManagedChromeButtons;
}
if(x.Item3)
{
ChromeHints |= ExtendClientAreaChromeHints.SystemTitleBar;
}
@ -127,6 +132,15 @@ namespace ControlCatalog.ViewModels
set { this.RaiseAndSetIfChanged(ref _systemChromeButtonsEnabled, value); }
}
private bool _managedChromeButtonsEnabled;
public bool ManagedChromeButtonsEnabled
{
get { return _managedChromeButtonsEnabled; }
set { this.RaiseAndSetIfChanged(ref _managedChromeButtonsEnabled, value); }
}
private double _titleBarHeight;
public double TitleBarHeight

34
src/Avalonia.Controls/Window.cs

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Controls.Chrome;
using Avalonia.Controls.Platform;
using Avalonia.Data;
using Avalonia.Input;
@ -69,7 +70,8 @@ namespace Avalonia.Controls
/// </summary>
public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot
{
private readonly List<(Window child, bool isDialog)> _children = new List<(Window, bool)>();
private readonly List<(Window child, bool isDialog)> _children = new List<(Window, bool)>();
private CaptionButtons _managedCaptions;
private bool _isExtendedIntoWindowDecorations;
@ -203,7 +205,15 @@ namespace Avalonia.Controls
(w, e) => { if (w.PlatformImpl != null) w.PlatformImpl.SetExtendClientAreaToDecorationsHint((bool)e.NewValue); });
ExtendClientAreaChromeHintsProperty.Changed.AddClassHandler<Window>(
(w, e) => { if (w.PlatformImpl != null) w.PlatformImpl.SetExtendClientAreaChromeHints((ExtendClientAreaChromeHints)e.NewValue); });
(w, e) =>
{
if (w.PlatformImpl != null)
{
w.PlatformImpl.SetExtendClientAreaChromeHints((ExtendClientAreaChromeHints)e.NewValue);
}
w.HandleChromeHintsChanged((ExtendClientAreaChromeHints)e.NewValue);
});
ExtendClientAreaTitleBarHeightHintProperty.Changed.AddClassHandler<Window>(
(w, e) => { if (w.PlatformImpl != null) w.PlatformImpl.SetExtendClientAreaTitleBarHeightHint((double)e.NewValue); });
@ -897,6 +907,26 @@ namespace Avalonia.Controls
base.HandleResized(clientSize);
}
private void HandleChromeHintsChanged (ExtendClientAreaChromeHints hints)
{
if(hints.HasFlag(ExtendClientAreaChromeHints.ManagedChromeButtons))
{
if(_managedCaptions == null)
{
_managedCaptions = new CaptionButtons(this);
}
_managedCaptions.Attach();
}
else
{
if(_managedCaptions != null)
{
_managedCaptions.Detach();
}
}
}
/// <summary>
/// Raises the <see cref="Closing"/> event.
/// </summary>

Loading…
Cancel
Save