From ad0e13dc1cbb1a5d464949af7c908dbc7334d3ea Mon Sep 17 00:00:00 2001 From: Mahdi Hosseini Date: Mon, 25 Nov 2024 15:08:24 +0330 Subject: [PATCH] Fix SettingsGroup AOT/Trim Crash --- .../SettingsGroup/SettingGroup.Property.cs | 19 ++++++++++++++----- .../SettingsGroup/SettingsGroup.cs | 1 + dev/DevWinUI.Controls/Themes/Generic.xaml | 2 +- .../Themes/Styles/Controls/SettingsGroup.xaml | 3 +-- .../SettingsControls.xaml | 0 .../SettingsControls.xaml.cs | 0 .../{Features => Settings}/SettingsGroup.xaml | 0 .../SettingsGroup.xaml.cs | 0 8 files changed, 17 insertions(+), 8 deletions(-) rename dev/DevWinUI.Gallery/Views/Pages/{Features => Settings}/SettingsControls.xaml (100%) rename dev/DevWinUI.Gallery/Views/Pages/{Features => Settings}/SettingsControls.xaml.cs (100%) rename dev/DevWinUI.Gallery/Views/Pages/{Features => Settings}/SettingsGroup.xaml (100%) rename dev/DevWinUI.Gallery/Views/Pages/{Features => Settings}/SettingsGroup.xaml.cs (100%) diff --git a/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingGroup.Property.cs b/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingGroup.Property.cs index a7991ff..9cd8c3c 100644 --- a/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingGroup.Property.cs +++ b/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingGroup.Property.cs @@ -4,6 +4,18 @@ namespace DevWinUI; public partial class SettingsGroup : Control { + internal CornerRadius RootGridCornerRadius + { + get { return (CornerRadius)GetValue(RootGridCornerRadiusProperty); } + set { SetValue(RootGridCornerRadiusProperty, value); } + } + + internal static readonly DependencyProperty RootGridCornerRadiusProperty = + DependencyProperty.Register(nameof(RootGridCornerRadius), typeof(CornerRadius), typeof(SettingsGroup), new PropertyMetadata(new CornerRadius(0))); + private CornerRadius GetRootGridCornerRadius() + { + return (CornerRadius)new Bool2CornerRadiusConverter().Convert(Items?.Count, null, null, null); + } public ObservableCollection Items { get { return (ObservableCollection)GetValue(ItemsProperty); } @@ -25,13 +37,10 @@ private void OnItemsChanged() { if (_itemsRepeater is not null) { - Bool2CornerRadiusConverter bool2CornerRadiusConverter = new Bool2CornerRadiusConverter(); - var cornerRadius = bool2CornerRadiusConverter.Convert(Items.Count, null, null, null); - + RootGridCornerRadius = GetRootGridCornerRadius(); if (_rootGrid != null) { - _rootGrid.CornerRadius = (CornerRadius)cornerRadius; - + _rootGrid.CornerRadius = GetRootGridCornerRadius(); } foreach (var item in Items) diff --git a/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingsGroup.cs b/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingsGroup.cs index 2c1b042..6b43e99 100644 --- a/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingsGroup.cs +++ b/dev/DevWinUI.Controls/Controls/SettingsGroup/SettingsGroup/SettingsGroup.cs @@ -57,6 +57,7 @@ protected override void OnApplyTemplate() OnHeaderChanged(); OnDescriptionChanged(); OnContentChanged(); + RootGridCornerRadius = GetRootGridCornerRadius(); base.OnApplyTemplate(); } diff --git a/dev/DevWinUI.Controls/Themes/Generic.xaml b/dev/DevWinUI.Controls/Themes/Generic.xaml index 5473ddc..b773647 100644 --- a/dev/DevWinUI.Controls/Themes/Generic.xaml +++ b/dev/DevWinUI.Controls/Themes/Generic.xaml @@ -3825,7 +3825,7 @@ Themes\Styles\Win2D\Watermark.xaml - + diff --git a/dev/DevWinUI.Controls/Themes/Styles/Controls/SettingsGroup.xaml b/dev/DevWinUI.Controls/Themes/Styles/Controls/SettingsGroup.xaml index b115193..13cacba 100644 --- a/dev/DevWinUI.Controls/Themes/Styles/Controls/SettingsGroup.xaml +++ b/dev/DevWinUI.Controls/Themes/Styles/Controls/SettingsGroup.xaml @@ -52,8 +52,7 @@ Background="{ThemeResource SettingsCardBackground}" BackgroundSizing="InnerBorderEdge" BorderBrush="{ThemeResource SettingsCardBorderBrush}" - BorderThickness="{ThemeResource SettingsCardBorderThickness}" - CornerRadius="{Binding Items.Count, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource Bool2CornerRadiusConverter}}"> + BorderThickness="{ThemeResource SettingsCardBorderThickness}"> diff --git a/dev/DevWinUI.Gallery/Views/Pages/Features/SettingsControls.xaml b/dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsControls.xaml similarity index 100% rename from dev/DevWinUI.Gallery/Views/Pages/Features/SettingsControls.xaml rename to dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsControls.xaml diff --git a/dev/DevWinUI.Gallery/Views/Pages/Features/SettingsControls.xaml.cs b/dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsControls.xaml.cs similarity index 100% rename from dev/DevWinUI.Gallery/Views/Pages/Features/SettingsControls.xaml.cs rename to dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsControls.xaml.cs diff --git a/dev/DevWinUI.Gallery/Views/Pages/Features/SettingsGroup.xaml b/dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsGroup.xaml similarity index 100% rename from dev/DevWinUI.Gallery/Views/Pages/Features/SettingsGroup.xaml rename to dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsGroup.xaml diff --git a/dev/DevWinUI.Gallery/Views/Pages/Features/SettingsGroup.xaml.cs b/dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsGroup.xaml.cs similarity index 100% rename from dev/DevWinUI.Gallery/Views/Pages/Features/SettingsGroup.xaml.cs rename to dev/DevWinUI.Gallery/Views/Pages/Settings/SettingsGroup.xaml.cs