From 25659176769ba350791039dbf7ae748f5e2aa404 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Tue, 22 Nov 2022 17:58:57 +0100 Subject: [PATCH 1/3] Small formatting --- src/Files.App/Helpers/ResourceHelpers.cs | 12 +- .../BaseObservableJsonSettings.cs | 17 +-- src/Files.App/Shell/ContextMenuItem.cs | 18 +-- .../Settings/SettingsBlockControl.xaml | 1 + .../Settings/SettingsBlockControl.xaml.cs | 122 ++++++------------ .../Settings/SettingsDisplayControl.xaml.cs | 52 +++----- 6 files changed, 73 insertions(+), 149 deletions(-) diff --git a/src/Files.App/Helpers/ResourceHelpers.cs b/src/Files.App/Helpers/ResourceHelpers.cs index 1f15fd71f616..db2d4b3faefc 100644 --- a/src/Files.App/Helpers/ResourceHelpers.cs +++ b/src/Files.App/Helpers/ResourceHelpers.cs @@ -6,16 +6,10 @@ namespace Files.App.Helpers [MarkupExtensionReturnType(ReturnType = typeof(string))] public sealed class ResourceString : MarkupExtension { - private static ResourceLoader resourceLoader = new ResourceLoader(); + private static readonly ResourceLoader loader = new(); - public string Name - { - get; set; - } + public string Name { get; set; } = string.Empty; - protected override object ProvideValue() - { - return resourceLoader.GetString(this.Name); - } + protected override object ProvideValue() => loader.GetString(Name); } } diff --git a/src/Files.App/Serialization/BaseObservableJsonSettings.cs b/src/Files.App/Serialization/BaseObservableJsonSettings.cs index b30f9f134fe1..f9d60ba6fee3 100644 --- a/src/Files.App/Serialization/BaseObservableJsonSettings.cs +++ b/src/Files.App/Serialization/BaseObservableJsonSettings.cs @@ -7,21 +7,16 @@ internal abstract class BaseObservableJsonSettings : BaseJsonSettings, INotifyPr { public event PropertyChangedEventHandler? PropertyChanged; - protected override bool Set(TValue? value, [CallerMemberName] string propertyName = "") - where TValue : default + protected override bool Set(TValue? value, [CallerMemberName] string propertyName = "") where TValue : default { - if (base.Set(value, propertyName)) - { - OnPropertyChanged(propertyName); - return true; - } + if (!base.Set(value, propertyName)) + return false; - return false; + OnPropertyChanged(propertyName); + return true; } protected void OnPropertyChanged([CallerMemberName] string propertyName = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } \ No newline at end of file diff --git a/src/Files.App/Shell/ContextMenuItem.cs b/src/Files.App/Shell/ContextMenuItem.cs index 0309c5b3347a..9b92f5011410 100644 --- a/src/Files.App/Shell/ContextMenuItem.cs +++ b/src/Files.App/Shell/ContextMenuItem.cs @@ -6,10 +6,7 @@ namespace Files.App.Shell { public class ContextMenuItem : Win32ContextMenuItem, IDisposable { - public ContextMenuItem() - { - SubItems = new List(); - } + public ContextMenuItem() => SubItems = new List(); public void Dispose() { @@ -19,17 +16,12 @@ public void Dispose() protected virtual void Dispose(bool disposing) { - if (disposing) + if (disposing && SubItems is not null) { - if (SubItems is not null) - { - foreach (var si in SubItems) - { - (si as IDisposable)?.Dispose(); - } + foreach (var subItem in SubItems) + (subItem as IDisposable)?.Dispose(); - SubItems = null; - } + SubItems = null; } } } diff --git a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml index 522ea64c677d..de02e2b6354e 100644 --- a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml +++ b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml @@ -8,6 +8,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="300" d:DesignWidth="400" + Loaded="SettingsBlockControl_Loaded" mc:Ignorable="d"> diff --git a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs index c7495ea7e308..70d582634ccc 100644 --- a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs +++ b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs @@ -10,48 +10,31 @@ namespace Files.App.UserControls.Settings [ContentProperty(Name = nameof(SettingsActionableElement))] public sealed partial class SettingsBlockControl : UserControl { - public FrameworkElement SettingsActionableElement { get; set; } + public event EventHandler? Click; - public ICommand ButtonCommand - { - get { return (ICommand)GetValue(ButtonCommandProperty); } - set { SetValue(ButtonCommandProperty, value); } - } - public static readonly DependencyProperty ButtonCommandProperty = - DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(SettingsBlockControl), new PropertyMetadata(null)); + public static readonly DependencyProperty TitleProperty = DependencyProperty + .Register(nameof(Title), typeof(string), typeof(SettingsBlockControl), new(null)); - public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty.Register( - "ExpandableContent", - typeof(FrameworkElement), - typeof(SettingsBlockControl), - new PropertyMetadata(null) - ); + public static readonly DependencyProperty DescriptionProperty = DependencyProperty + .Register(nameof(Description), typeof(string), typeof(SettingsBlockControl), new(null)); - public FrameworkElement ExpandableContent - { - get => (FrameworkElement)GetValue(ExpandableContentProperty); - set => SetValue(ExpandableContentProperty, value); - } + public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty + .Register(nameof(AdditionalDescriptionContent), typeof(FrameworkElement), typeof(SettingsBlockControl), new(null)); - public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register( - "AdditionalDescriptionContent", - typeof(FrameworkElement), - typeof(SettingsBlockControl), - new PropertyMetadata(null) - ); + public static readonly DependencyProperty IconProperty = DependencyProperty + .Register(nameof(Icon), typeof(IconElement), typeof(SettingsBlockControl), new(null)); - public FrameworkElement AdditionalDescriptionContent - { - get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); - set => SetValue(AdditionalDescriptionContentProperty, value); - } + public static readonly DependencyProperty ButtonCommandProperty = DependencyProperty + .Register(nameof(ButtonCommand), typeof(ICommand), typeof(SettingsBlockControl), new(null)); + + public static readonly DependencyProperty IsClickableProperty = DependencyProperty + .Register(nameof(IsClickable), typeof(bool), typeof(SettingsBlockControl), new(false)); - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - "Title", - typeof(string), - typeof(SettingsBlockControl), - new PropertyMetadata(null) - ); + public static readonly DependencyProperty IsExpandedProperty = DependencyProperty + .Register(nameof(IsExpanded), typeof(bool), typeof(SettingsBlockControl), new(false)); + + public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty + .Register(nameof(ExpandableContent), typeof(FrameworkElement), typeof(SettingsBlockControl), new(null)); public string Title { @@ -59,25 +42,17 @@ public string Title set => SetValue(TitleProperty, value); } - public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( - "Description", - typeof(string), - typeof(SettingsBlockControl), - new PropertyMetadata(null) - ); - public string Description { get => (string)GetValue(DescriptionProperty); set => SetValue(DescriptionProperty, value); } - public static readonly DependencyProperty IconProperty = DependencyProperty.Register( - "Icon", - typeof(IconElement), - typeof(SettingsBlockControl), - new PropertyMetadata(null) - ); + public FrameworkElement AdditionalDescriptionContent + { + get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); + set => SetValue(AdditionalDescriptionContentProperty, value); + } public IconElement Icon { @@ -85,12 +60,11 @@ public IconElement Icon set => SetValue(IconProperty, value); } - public static readonly DependencyProperty IsClickableProperty = DependencyProperty.Register( - "IsClickable", - typeof(bool), - typeof(SettingsBlockControl), - new PropertyMetadata(false) - ); + public ICommand ButtonCommand + { + get => (ICommand)GetValue(ButtonCommandProperty); + set => SetValue(ButtonCommandProperty, value); + } public bool IsClickable { @@ -98,46 +72,30 @@ public bool IsClickable set => SetValue(IsClickableProperty, value); } - public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register( - "IsExpanded", - typeof(bool), - typeof(SettingsBlockControl), - new PropertyMetadata(false) - ); - public bool IsExpanded { get => (bool)GetValue(IsExpandedProperty); set => SetValue(IsExpandedProperty, value); } - // - // Summary: - // Occurs when a button control is clicked. - public event EventHandler Click; - - public SettingsBlockControl() + public FrameworkElement ExpandableContent { - this.InitializeComponent(); - this.Loaded += SettingsBlockControl_Loaded; + get => (FrameworkElement)GetValue(ExpandableContentProperty); + set => SetValue(ExpandableContentProperty, value); } - private void SettingsBlockControl_Loaded(object sender, RoutedEventArgs e) + public FrameworkElement? SettingsActionableElement { get; set; } + + public SettingsBlockControl() => InitializeComponent(); + + private void SettingsBlockControl_Loaded(object _, RoutedEventArgs e) { + Loaded -= SettingsBlockControl_Loaded; if (ActionableButton is not null) - { AutomationProperties.SetName(ActionableButton, Title); - } } - private void Expander_Expanding(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderExpandingEventArgs args) - { - Click?.Invoke(this, true); - } - - private void Expander_Collapsed(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderCollapsedEventArgs args) - { - Click?.Invoke(this, false); - } + private void Expander_Collapsed(Expander _, ExpanderCollapsedEventArgs e) => Click?.Invoke(this, false); + private void Expander_Expanding(Expander _, ExpanderExpandingEventArgs e) => Click?.Invoke(this, true); } } \ No newline at end of file diff --git a/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs b/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs index abcbc3c85d26..3197488c25ca 100644 --- a/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs +++ b/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs @@ -7,27 +7,17 @@ namespace Files.App.UserControls.Settings [ContentProperty(Name = nameof(SettingsActionableElement))] public sealed partial class SettingsDisplayControl : UserControl { - public FrameworkElement SettingsActionableElement { get; set; } + public static readonly DependencyProperty TitleProperty = DependencyProperty + .Register(nameof(Title), typeof(string), typeof(SettingsDisplayControl), new(null)); - public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register( - "AdditionalDescriptionContent", - typeof(FrameworkElement), - typeof(SettingsDisplayControl), - new PropertyMetadata(null) - ); + public static readonly DependencyProperty DescriptionProperty = DependencyProperty + .Register(nameof(Description), typeof(string), typeof(SettingsDisplayControl), new(null)); - public FrameworkElement AdditionalDescriptionContent - { - get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); - set => SetValue(AdditionalDescriptionContentProperty, value); - } + public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty + .Register(nameof(AdditionalDescriptionContent), typeof(FrameworkElement), typeof(SettingsDisplayControl), new(null)); - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - "Title", - typeof(string), - typeof(SettingsDisplayControl), - new PropertyMetadata(null) - ); + public static readonly DependencyProperty IconProperty = DependencyProperty + .Register(nameof(Icon), typeof(IconElement), typeof(SettingsDisplayControl), new(null)); public string Title { @@ -35,25 +25,17 @@ public string Title set => SetValue(TitleProperty, value); } - public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( - "Description", - typeof(string), - typeof(SettingsDisplayControl), - new PropertyMetadata(null) - ); - public string Description { get => (string)GetValue(DescriptionProperty); set => SetValue(DescriptionProperty, value); } - public static readonly DependencyProperty IconProperty = DependencyProperty.Register( - "Icon", - typeof(IconElement), - typeof(SettingsDisplayControl), - new PropertyMetadata(null) - ); + public FrameworkElement AdditionalDescriptionContent + { + get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); + set => SetValue(AdditionalDescriptionContentProperty, value); + } public IconElement Icon { @@ -61,15 +43,17 @@ public IconElement Icon set => SetValue(IconProperty, value); } + public FrameworkElement? SettingsActionableElement { get; set; } + public SettingsDisplayControl() { - this.InitializeComponent(); + InitializeComponent(); VisualStateManager.GoToState(this, "NormalState", false); } - private void MainPanel_SizeChanged(object sender, SizeChangedEventArgs e) + private void MainPanel_SizeChanged(object _, SizeChangedEventArgs e) { - if (e.NewSize.Width == e.PreviousSize.Width || ActionableElement is null) + if (ActionableElement is null || e.NewSize.Width == e.PreviousSize.Width) return; var stateToGoName = (ActionableElement.ActualWidth > e.NewSize.Width / 3) ? "CompactState" : "NormalState"; From 9ef6b282e63264e6d58c3760d95136b78f4fbfb8 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Fri, 23 Dec 2022 07:35:40 +0100 Subject: [PATCH 2/3] changes --- src/Files.App/Helpers/ResourceHelpers.cs | 4 +- .../Settings/SettingsBlockControl.xaml | 1 - .../Settings/SettingsBlockControl.xaml.cs | 122 ++++++++++++------ 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/src/Files.App/Helpers/ResourceHelpers.cs b/src/Files.App/Helpers/ResourceHelpers.cs index db2d4b3faefc..3bb5db168427 100644 --- a/src/Files.App/Helpers/ResourceHelpers.cs +++ b/src/Files.App/Helpers/ResourceHelpers.cs @@ -6,10 +6,10 @@ namespace Files.App.Helpers [MarkupExtensionReturnType(ReturnType = typeof(string))] public sealed class ResourceString : MarkupExtension { - private static readonly ResourceLoader loader = new(); + private static readonly ResourceLoader resourceLoader = new(); public string Name { get; set; } = string.Empty; - protected override object ProvideValue() => loader.GetString(Name); + protected override object ProvideValue() => resourceLoader.GetString(Name); } } diff --git a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml index de02e2b6354e..522ea64c677d 100644 --- a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml +++ b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml @@ -8,7 +8,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="300" d:DesignWidth="400" - Loaded="SettingsBlockControl_Loaded" mc:Ignorable="d"> diff --git a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs index 70d582634ccc..c7495ea7e308 100644 --- a/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs +++ b/src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs @@ -10,31 +10,48 @@ namespace Files.App.UserControls.Settings [ContentProperty(Name = nameof(SettingsActionableElement))] public sealed partial class SettingsBlockControl : UserControl { - public event EventHandler? Click; + public FrameworkElement SettingsActionableElement { get; set; } - public static readonly DependencyProperty TitleProperty = DependencyProperty - .Register(nameof(Title), typeof(string), typeof(SettingsBlockControl), new(null)); - - public static readonly DependencyProperty DescriptionProperty = DependencyProperty - .Register(nameof(Description), typeof(string), typeof(SettingsBlockControl), new(null)); - - public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty - .Register(nameof(AdditionalDescriptionContent), typeof(FrameworkElement), typeof(SettingsBlockControl), new(null)); + public ICommand ButtonCommand + { + get { return (ICommand)GetValue(ButtonCommandProperty); } + set { SetValue(ButtonCommandProperty, value); } + } + public static readonly DependencyProperty ButtonCommandProperty = + DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(SettingsBlockControl), new PropertyMetadata(null)); - public static readonly DependencyProperty IconProperty = DependencyProperty - .Register(nameof(Icon), typeof(IconElement), typeof(SettingsBlockControl), new(null)); + public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty.Register( + "ExpandableContent", + typeof(FrameworkElement), + typeof(SettingsBlockControl), + new PropertyMetadata(null) + ); - public static readonly DependencyProperty ButtonCommandProperty = DependencyProperty - .Register(nameof(ButtonCommand), typeof(ICommand), typeof(SettingsBlockControl), new(null)); + public FrameworkElement ExpandableContent + { + get => (FrameworkElement)GetValue(ExpandableContentProperty); + set => SetValue(ExpandableContentProperty, value); + } - public static readonly DependencyProperty IsClickableProperty = DependencyProperty - .Register(nameof(IsClickable), typeof(bool), typeof(SettingsBlockControl), new(false)); + public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register( + "AdditionalDescriptionContent", + typeof(FrameworkElement), + typeof(SettingsBlockControl), + new PropertyMetadata(null) + ); - public static readonly DependencyProperty IsExpandedProperty = DependencyProperty - .Register(nameof(IsExpanded), typeof(bool), typeof(SettingsBlockControl), new(false)); + public FrameworkElement AdditionalDescriptionContent + { + get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); + set => SetValue(AdditionalDescriptionContentProperty, value); + } - public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty - .Register(nameof(ExpandableContent), typeof(FrameworkElement), typeof(SettingsBlockControl), new(null)); + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( + "Title", + typeof(string), + typeof(SettingsBlockControl), + new PropertyMetadata(null) + ); public string Title { @@ -42,17 +59,25 @@ public string Title set => SetValue(TitleProperty, value); } + public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( + "Description", + typeof(string), + typeof(SettingsBlockControl), + new PropertyMetadata(null) + ); + public string Description { get => (string)GetValue(DescriptionProperty); set => SetValue(DescriptionProperty, value); } - public FrameworkElement AdditionalDescriptionContent - { - get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); - set => SetValue(AdditionalDescriptionContentProperty, value); - } + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + "Icon", + typeof(IconElement), + typeof(SettingsBlockControl), + new PropertyMetadata(null) + ); public IconElement Icon { @@ -60,11 +85,12 @@ public IconElement Icon set => SetValue(IconProperty, value); } - public ICommand ButtonCommand - { - get => (ICommand)GetValue(ButtonCommandProperty); - set => SetValue(ButtonCommandProperty, value); - } + public static readonly DependencyProperty IsClickableProperty = DependencyProperty.Register( + "IsClickable", + typeof(bool), + typeof(SettingsBlockControl), + new PropertyMetadata(false) + ); public bool IsClickable { @@ -72,30 +98,46 @@ public bool IsClickable set => SetValue(IsClickableProperty, value); } + public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register( + "IsExpanded", + typeof(bool), + typeof(SettingsBlockControl), + new PropertyMetadata(false) + ); + public bool IsExpanded { get => (bool)GetValue(IsExpandedProperty); set => SetValue(IsExpandedProperty, value); } - public FrameworkElement ExpandableContent + // + // Summary: + // Occurs when a button control is clicked. + public event EventHandler Click; + + public SettingsBlockControl() { - get => (FrameworkElement)GetValue(ExpandableContentProperty); - set => SetValue(ExpandableContentProperty, value); + this.InitializeComponent(); + this.Loaded += SettingsBlockControl_Loaded; } - public FrameworkElement? SettingsActionableElement { get; set; } - - public SettingsBlockControl() => InitializeComponent(); - - private void SettingsBlockControl_Loaded(object _, RoutedEventArgs e) + private void SettingsBlockControl_Loaded(object sender, RoutedEventArgs e) { - Loaded -= SettingsBlockControl_Loaded; if (ActionableButton is not null) + { AutomationProperties.SetName(ActionableButton, Title); + } } - private void Expander_Collapsed(Expander _, ExpanderCollapsedEventArgs e) => Click?.Invoke(this, false); - private void Expander_Expanding(Expander _, ExpanderExpandingEventArgs e) => Click?.Invoke(this, true); + private void Expander_Expanding(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderExpandingEventArgs args) + { + Click?.Invoke(this, true); + } + + private void Expander_Collapsed(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderCollapsedEventArgs args) + { + Click?.Invoke(this, false); + } } } \ No newline at end of file From 841020462336889b2037f69b962fdcd680dc16af Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Fri, 30 Dec 2022 14:08:38 +0100 Subject: [PATCH 3/3] Undo SettingsDisplayControl --- .../Settings/SettingsDisplayControl.xaml.cs | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs b/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs index 3197488c25ca..abcbc3c85d26 100644 --- a/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs +++ b/src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs @@ -7,17 +7,27 @@ namespace Files.App.UserControls.Settings [ContentProperty(Name = nameof(SettingsActionableElement))] public sealed partial class SettingsDisplayControl : UserControl { - public static readonly DependencyProperty TitleProperty = DependencyProperty - .Register(nameof(Title), typeof(string), typeof(SettingsDisplayControl), new(null)); + public FrameworkElement SettingsActionableElement { get; set; } - public static readonly DependencyProperty DescriptionProperty = DependencyProperty - .Register(nameof(Description), typeof(string), typeof(SettingsDisplayControl), new(null)); + public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register( + "AdditionalDescriptionContent", + typeof(FrameworkElement), + typeof(SettingsDisplayControl), + new PropertyMetadata(null) + ); - public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty - .Register(nameof(AdditionalDescriptionContent), typeof(FrameworkElement), typeof(SettingsDisplayControl), new(null)); + public FrameworkElement AdditionalDescriptionContent + { + get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); + set => SetValue(AdditionalDescriptionContentProperty, value); + } - public static readonly DependencyProperty IconProperty = DependencyProperty - .Register(nameof(Icon), typeof(IconElement), typeof(SettingsDisplayControl), new(null)); + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( + "Title", + typeof(string), + typeof(SettingsDisplayControl), + new PropertyMetadata(null) + ); public string Title { @@ -25,17 +35,25 @@ public string Title set => SetValue(TitleProperty, value); } + public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( + "Description", + typeof(string), + typeof(SettingsDisplayControl), + new PropertyMetadata(null) + ); + public string Description { get => (string)GetValue(DescriptionProperty); set => SetValue(DescriptionProperty, value); } - public FrameworkElement AdditionalDescriptionContent - { - get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty); - set => SetValue(AdditionalDescriptionContentProperty, value); - } + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + "Icon", + typeof(IconElement), + typeof(SettingsDisplayControl), + new PropertyMetadata(null) + ); public IconElement Icon { @@ -43,17 +61,15 @@ public IconElement Icon set => SetValue(IconProperty, value); } - public FrameworkElement? SettingsActionableElement { get; set; } - public SettingsDisplayControl() { - InitializeComponent(); + this.InitializeComponent(); VisualStateManager.GoToState(this, "NormalState", false); } - private void MainPanel_SizeChanged(object _, SizeChangedEventArgs e) + private void MainPanel_SizeChanged(object sender, SizeChangedEventArgs e) { - if (ActionableElement is null || e.NewSize.Width == e.PreviousSize.Width) + if (e.NewSize.Width == e.PreviousSize.Width || ActionableElement is null) return; var stateToGoName = (ActionableElement.ActualWidth > e.NewSize.Width / 3) ? "CompactState" : "NormalState";