Browse Source

Add a WindowCustomization page to the control catalog.

Dan Walmsley 5 years ago
parent
commit
454cc06184

+ 1 - 0
samples/ControlCatalog/MainView.xaml

@@ -61,6 +61,7 @@
       <TabItem Header="ToolTip"><pages:ToolTipPage/></TabItem>
       <TabItem Header="TreeView"><pages:TreeViewPage/></TabItem>
       <TabItem Header="Viewbox"><pages:ViewboxPage/></TabItem>
+      <TabItem Header="Window Customizations"><pages:WindowCustomizationsPage/></TabItem>
       <TabControl.Tag>
         <StackPanel Width="115" Spacing="4" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="8">
           <ComboBox x:Name="Decorations" SelectedIndex="0">

+ 6 - 2
samples/ControlCatalog/MainWindow.xaml

@@ -7,7 +7,11 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:vm="clr-namespace:ControlCatalog.ViewModels"
         xmlns:v="clr-namespace:ControlCatalog.Views"
-        x:Class="ControlCatalog.MainWindow" WindowState="{Binding WindowState, Mode=TwoWay}" Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}">
+        ExtendClientAreaToDecorationsHint="{Binding ExtendClientAreaEnabled}"
+        ExtendClientAreaChromeHints="{Binding ChromeHints}"
+        ExtendClientAreaTitleBarHeightHint="{Binding TitleBarHeight}"
+        x:Name="MainWindow"
+        x:Class="ControlCatalog.MainWindow" WindowState="{Binding WindowState, Mode=TwoWay}" Background="{x:Null}">
   <NativeMenu.Menu>
     <NativeMenu>
       <NativeMenuItem Header="File">
@@ -61,7 +65,7 @@
       <v:CustomNotificationView />
     </DataTemplate>
   </Window.DataTemplates>
-  <DockPanel LastChildFill="True">
+  <DockPanel LastChildFill="True" Margin="{Binding #MainWindow.WindowDecorationMargins}">
     <Menu Name="MainMenu" DockPanel.Dock="Top">
       <MenuItem Header="File">
         <MenuItem Header="Exit" Command="{Binding ExitCommand}" />

+ 13 - 0
samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml

@@ -0,0 +1,13 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:Class="ControlCatalog.Pages.WindowCustomizationsPage">
+  <StackPanel Spacing="10" Margin="15">    
+    <CheckBox Content="Extend Client Area to Decorations" IsChecked="{Binding ExtendClientAreaEnabled}" />
+    <CheckBox Content="Titlebar" IsChecked="{Binding SystemTitleBarEnabled}" />
+    <CheckBox Content="System Chrome Buttons" IsChecked="{Binding SystemChromeButtonsEnabled}" />
+    <Slider Minimum="-1" Maximum="200" Value="{Binding TitleBarHeight}" />
+  </StackPanel>
+</UserControl>

+ 19 - 0
samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml.cs

@@ -0,0 +1,19 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace ControlCatalog.Pages
+{
+    public class WindowCustomizationsPage : UserControl
+    {
+        public WindowCustomizationsPage()
+        {
+            this.InitializeComponent();
+        }
+
+        private void InitializeComponent()
+        {
+            AvaloniaXamlLoader.Load(this);
+        }
+    }
+}

+ 60 - 0
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@@ -3,6 +3,8 @@ using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Notifications;
 using Avalonia.Dialogs;
+using Avalonia.Platform;
+using System;
 using ReactiveUI;
 
 namespace ControlCatalog.ViewModels
@@ -62,8 +64,66 @@ namespace ControlCatalog.ViewModels
                 WindowState.Maximized,
                 WindowState.FullScreen,
             };
+
+            this.WhenAnyValue(x => x.SystemChromeButtonsEnabled, x => x.SystemTitleBarEnabled)
+                .Subscribe(x =>
+                {
+                    ChromeHints = ExtendClientAreaChromeHints.NoChrome;
+
+                    if(x.Item1)
+                    {
+                        ChromeHints |= ExtendClientAreaChromeHints.SystemChromeButtons;
+                    }
+
+                    if(x.Item2)
+                    {
+                        ChromeHints |= ExtendClientAreaChromeHints.SystemTitleBar;
+                    }
+                });
+        }
+
+        private ExtendClientAreaChromeHints _chromeHints;
+
+        public ExtendClientAreaChromeHints ChromeHints
+        {
+            get { return _chromeHints; }
+            set { this.RaiseAndSetIfChanged(ref _chromeHints, value); }
+        }
+
+
+        private bool _extendClientAreaEnabled;
+
+        public bool ExtendClientAreaEnabled
+        {
+            get { return _extendClientAreaEnabled; }
+            set { this.RaiseAndSetIfChanged(ref _extendClientAreaEnabled, value); }
         }
 
+        private bool _systemTitleBarEnabled;
+
+        public bool SystemTitleBarEnabled
+        {
+            get { return _systemTitleBarEnabled; }
+            set { this.RaiseAndSetIfChanged(ref _systemTitleBarEnabled, value); }
+        }
+
+        private bool _systemChromeButtonsEnabled;
+
+        public bool SystemChromeButtonsEnabled
+        {
+            get { return _systemChromeButtonsEnabled; }
+            set { this.RaiseAndSetIfChanged(ref _systemChromeButtonsEnabled, value); }
+        }
+
+        private double _titleBarHeight;
+
+        public double TitleBarHeight
+        {
+            get { return _titleBarHeight; }
+            set { this.RaiseAndSetIfChanged(ref _titleBarHeight, value); }
+        }
+
+
         public WindowState WindowState
         {
             get { return _windowState; }