From 075d92f754e576ac0651110c23631b50611a3bdc Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 6 Nov 2023 12:18:05 +0800 Subject: [PATCH 1/3] Set IsEnabled by a new property instead of setting it separately for each SettingsCard --- .../Snap.Hutao/View/Page/LaunchGamePage.xaml | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml index 80c2ca8c..dfef36b1 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml @@ -12,6 +12,7 @@ xmlns:shc="using:Snap.Hutao.Control" xmlns:shcb="using:Snap.Hutao.Control.Behavior" xmlns:shccs="using:Snap.Hutao.Control.Collection.Selector" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shcm="using:Snap.Hutao.Control.Markup" xmlns:shvc="using:Snap.Hutao.View.Control" xmlns:shvg="using:Snap.Hutao.ViewModel.Game" @@ -202,25 +203,17 @@ Description="{shcm:ResourceString Name=ViewPageLaunchGameArgumentsDescription}" Header="{shcm:ResourceString Name=ViewPageLaunchGameArgumentsHeader}" HeaderIcon="{shcm:FontIcon Glyph=}" - IsExpanded="True"> + IsExpanded="True" + shch:SettingsExpanderHelper.IsItemsEnabled="{Binding Options.IsEnabled}"> - + - + - + @@ -230,10 +223,7 @@ ItemsSource="{Binding Options.AspectRatios}" SelectedItem="{Binding Options.SelectedAspectRatio, Mode=TwoWay}"/> - + - + - + Date: Mon, 6 Nov 2023 12:32:22 +0800 Subject: [PATCH 2/3] Add files --- .../Control/Helper/SettingsExpanderHelper.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs b/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs new file mode 100644 index 00000000..50346c26 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs @@ -0,0 +1,21 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using CommunityToolkit.WinUI.Controls; +using Microsoft.UI.Xaml; + +namespace Snap.Hutao.Control.Helper; + +[SuppressMessage("", "SH001")] +[DependencyProperty("IsItemsEnabled", typeof(bool), true, nameof(OnIsItemsEnabledChanged), IsAttached = true, AttachedType = typeof(SettingsExpander))] +public sealed partial class SettingsExpanderHelper +{ + private static void OnIsItemsEnabledChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e) + { + SettingsExpander expander = (SettingsExpander)dp; + foreach (SettingsCard item in expander.Items.Cast()) + { + item.IsEnabled = (bool)e.NewValue; + } + } +} From 88684bff004f9cdd2ea0d31a08319d5b80c5d395 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Mon, 6 Nov 2023 12:40:19 +0800 Subject: [PATCH 3/3] code style --- .../Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs | 8 +++++--- src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs b/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs index 50346c26..3d3b9540 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Helper/SettingsExpanderHelper.cs @@ -12,10 +12,12 @@ public sealed partial class SettingsExpanderHelper { private static void OnIsItemsEnabledChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e) { - SettingsExpander expander = (SettingsExpander)dp; - foreach (SettingsCard item in expander.Items.Cast()) + foreach (object item in ((SettingsExpander)dp).Items) { - item.IsEnabled = (bool)e.NewValue; + if (item is Microsoft.UI.Xaml.Controls.Control control) + { + control.IsEnabled = (bool)e.NewValue; + } } } } diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml index dfef36b1..8566e7f2 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml @@ -200,11 +200,11 @@ + IsExpanded="True">