Browse Source

Update view transparency selection on the control catalog

pull/9658/head
Max Katz 4 years ago
parent
commit
08a494ac7d
  1. 3
      samples/ControlCatalog/MainView.xaml
  2. 23
      samples/ControlCatalog/MainView.xaml.cs
  3. 1
      samples/ControlCatalog/MainWindow.xaml
  4. 7
      samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml
  5. 7
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

3
samples/ControlCatalog/MainView.xaml

@ -206,8 +206,7 @@
</ComboBox.Items> </ComboBox.Items>
</ComboBox> </ComboBox>
<ComboBox x:Name="TransparencyLevels" <ComboBox x:Name="TransparencyLevels"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch">
SelectedIndex="{Binding TransparencyLevel}">
<ComboBox.Items> <ComboBox.Items>
<WindowTransparencyLevel>None</WindowTransparencyLevel> <WindowTransparencyLevel>None</WindowTransparencyLevel>
<WindowTransparencyLevel>Transparent</WindowTransparencyLevel> <WindowTransparencyLevel>Transparent</WindowTransparencyLevel>

23
samples/ControlCatalog/MainView.xaml.cs

@ -6,6 +6,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Immutable; using Avalonia.Media.Immutable;
using Avalonia.VisualTree;
using ControlCatalog.Models; using ControlCatalog.Models;
using ControlCatalog.Pages; using ControlCatalog.Pages;
@ -59,17 +60,25 @@ namespace ControlCatalog
}; };
var transparencyLevels = this.Get<ComboBox>("TransparencyLevels"); var transparencyLevels = this.Get<ComboBox>("TransparencyLevels");
IDisposable? backgroundSetter = null, paneBackgroundSetter = null; IDisposable? topLevelBackgroundSideSetter = null, sideBarBackgroundSetter = null, paneBackgroundSetter = null;
transparencyLevels.SelectionChanged += (sender, e) => transparencyLevels.SelectionChanged += (sender, e) =>
{ {
backgroundSetter?.Dispose(); topLevelBackgroundSideSetter?.Dispose();
sideBarBackgroundSetter?.Dispose();
paneBackgroundSetter?.Dispose(); paneBackgroundSetter?.Dispose();
if (transparencyLevels.SelectedItem is WindowTransparencyLevel selected if (transparencyLevels.SelectedItem is WindowTransparencyLevel selected)
&& selected != WindowTransparencyLevel.None)
{ {
var semiTransparentBrush = new ImmutableSolidColorBrush(Colors.Gray, 0.5); var topLevel = (TopLevel)this.GetVisualRoot()!;
backgroundSetter = sideBar.SetValue(BackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style); topLevel.TransparencyLevelHint = selected;
paneBackgroundSetter = sideBar.SetValue(SplitView.PaneBackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style);
if (selected != WindowTransparencyLevel.None)
{
var transparentBrush = new ImmutableSolidColorBrush(Colors.White, 0);
var semiTransparentBrush = new ImmutableSolidColorBrush(Colors.Gray, 0.2);
topLevelBackgroundSideSetter = topLevel.SetValue(BackgroundProperty, transparentBrush, Avalonia.Data.BindingPriority.Style);
sideBarBackgroundSetter = sideBar.SetValue(BackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style);
paneBackgroundSetter = sideBar.SetValue(SplitView.PaneBackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style);
}
} }
}; };
} }

1
samples/ControlCatalog/MainWindow.xaml

@ -10,7 +10,6 @@
ExtendClientAreaToDecorationsHint="{Binding ExtendClientAreaEnabled}" ExtendClientAreaToDecorationsHint="{Binding ExtendClientAreaEnabled}"
ExtendClientAreaChromeHints="{Binding ChromeHints}" ExtendClientAreaChromeHints="{Binding ChromeHints}"
ExtendClientAreaTitleBarHeightHint="{Binding TitleBarHeight}" ExtendClientAreaTitleBarHeightHint="{Binding TitleBarHeight}"
TransparencyLevelHint="{Binding TransparencyLevel}"
x:Name="MainWindow" x:Name="MainWindow"
Background="Transparent" Background="Transparent"
x:Class="ControlCatalog.MainWindow" WindowState="{Binding WindowState, Mode=TwoWay}" x:Class="ControlCatalog.MainWindow" WindowState="{Binding WindowState, Mode=TwoWay}"

7
samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml

@ -11,12 +11,5 @@
<CheckBox Content="Title Bar" IsChecked="{Binding SystemTitleBarEnabled}" /> <CheckBox Content="Title Bar" IsChecked="{Binding SystemTitleBarEnabled}" />
<CheckBox Content="Prefer System Chrome" IsChecked="{Binding PreferSystemChromeEnabled}" /> <CheckBox Content="Prefer System Chrome" IsChecked="{Binding PreferSystemChromeEnabled}" />
<Slider Minimum="-1" Maximum="200" Value="{Binding TitleBarHeight}" /> <Slider Minimum="-1" Maximum="200" Value="{Binding TitleBarHeight}" />
<ComboBox x:Name="TransparencyLevels" SelectedIndex="{Binding TransparencyLevel}">
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Transparent</ComboBoxItem>
<ComboBoxItem>Blur</ComboBoxItem>
<ComboBoxItem>AcrylicBlur</ComboBoxItem>
<ComboBoxItem>Mica</ComboBoxItem>
</ComboBox>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

7
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@ -17,7 +17,6 @@ namespace ControlCatalog.ViewModels
private bool _isMenuItemChecked = true; private bool _isMenuItemChecked = true;
private WindowState _windowState; private WindowState _windowState;
private WindowState[] _windowStates = Array.Empty<WindowState>(); private WindowState[] _windowStates = Array.Empty<WindowState>();
private int _transparencyLevel;
private ExtendClientAreaChromeHints _chromeHints = ExtendClientAreaChromeHints.PreferSystemChrome; private ExtendClientAreaChromeHints _chromeHints = ExtendClientAreaChromeHints.PreferSystemChrome;
private bool _extendClientAreaEnabled; private bool _extendClientAreaEnabled;
private bool _systemTitleBarEnabled; private bool _systemTitleBarEnabled;
@ -77,12 +76,6 @@ namespace ControlCatalog.ViewModels
TitleBarHeight = -1; TitleBarHeight = -1;
} }
public int TransparencyLevel
{
get { return _transparencyLevel; }
set { this.RaiseAndSetIfChanged(ref _transparencyLevel, value); }
}
public ExtendClientAreaChromeHints ChromeHints public ExtendClientAreaChromeHints ChromeHints
{ {
get { return _chromeHints; } get { return _chromeHints; }

Loading…
Cancel
Save