diff --git a/Directory.Packages.props b/Directory.Packages.props index bfb0a0d9c9..7ef244b355 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,7 +7,7 @@ - + diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index ea71773d13..f7b2658b0f 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -25,6 +25,9 @@ 20 10 + @@ -90,7 +93,8 @@ Header="Settings" Margin="0" BorderThickness="0" - ExpandDirection="Up"> + ExpandDirection="Up" + x:Name="SettingsExpander"> typeof(MainView); + private void MainView_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { if (DataContext == null) @@ -120,21 +122,21 @@ namespace ControlCatalog private void TransparencyLevels_SelectionChanged(object? sender, SelectionChangedEventArgs e) { - _disposeTransparencySetters?.Invoke(); - if (TopLevel.GetTopLevel(this) is { } topLevel && e.AddedItems.Count > 0 && e.AddedItems[0] is WindowTransparencyLevel transparencyLevel) { topLevel.TransparencyLevelHint = [transparencyLevel]; if (topLevel.ActualTransparencyLevel != WindowTransparencyLevel.None && - topLevel.ActualTransparencyLevel == transparencyLevel) + transparencyLevel != WindowTransparencyLevel.None) + { + topLevel.Background = new ImmutableSolidColorBrush(Colors.Gray, 0.2); + if (!topLevel.Styles.Contains(_transparentStyles)) + topLevel.Styles.Add(_transparentStyles); + } + else { - var transparentBrush = new ImmutableSolidColorBrush(Colors.White, 0); - var semiTransparentBrush = new ImmutableSolidColorBrush(Colors.Gray, 0.2); - _disposeTransparencySetters = - (Action)topLevel.SetValue(BackgroundProperty, transparentBrush, Avalonia.Data.BindingPriority.Style)!.Dispose + - SetValue(BackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style)!.Dispose + - SetValue(DrawerPage.DrawerBackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style)!.Dispose; + topLevel.Background = null; + topLevel.Styles.Remove(_transparentStyles); } } } diff --git a/samples/ControlCatalog/MainWindow.xaml b/samples/ControlCatalog/MainWindow.xaml index b466315878..4c0118872b 100644 --- a/samples/ControlCatalog/MainWindow.xaml +++ b/samples/ControlCatalog/MainWindow.xaml @@ -12,7 +12,6 @@ CanResize="{Binding CanResize}" CanMinimize="{Binding CanMinimize}" CanMaximize="{Binding CanMaximize}" - Background="Transparent" x:Class="ControlCatalog.MainWindow" WindowState="{Binding WindowState, Mode=TwoWay}" x:DataType="vm:MainWindowViewModel"> @@ -60,11 +59,20 @@ - + - + - + diff --git a/samples/ControlCatalog/TransparentStyles.axaml b/samples/ControlCatalog/TransparentStyles.axaml new file mode 100644 index 0000000000..adf9244627 --- /dev/null +++ b/samples/ControlCatalog/TransparentStyles.axaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + diff --git a/samples/ControlCatalog/TransparentStyles.axaml.cs b/samples/ControlCatalog/TransparentStyles.axaml.cs new file mode 100644 index 0000000000..85310f4b09 --- /dev/null +++ b/samples/ControlCatalog/TransparentStyles.axaml.cs @@ -0,0 +1,5 @@ +using Avalonia.Styling; + +namespace ControlCatalog; + +public class TransparentStyles : Styles;