diff --git a/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj b/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj index 7d92f013..9ce50fa8 100644 --- a/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj +++ b/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj @@ -51,8 +51,8 @@ - - + + diff --git a/sample/Atc.Wpf.Sample/SamplesWpf/Controls/Layouts/StaggeredPanelView.xaml b/sample/Atc.Wpf.Sample/SamplesWpf/Controls/Layouts/StaggeredPanelView.xaml index 8147e312..d7b0c63e 100644 --- a/sample/Atc.Wpf.Sample/SamplesWpf/Controls/Layouts/StaggeredPanelView.xaml +++ b/sample/Atc.Wpf.Sample/SamplesWpf/Controls/Layouts/StaggeredPanelView.xaml @@ -28,64 +28,62 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - diff --git a/sample/Atc.Wpf.Sample/SamplesWpfControls/ColorControls/WellKnownColorPickerView.xaml b/sample/Atc.Wpf.Sample/SamplesWpfControls/ColorControls/WellKnownColorPickerView.xaml index aeb5f064..1a313031 100644 --- a/sample/Atc.Wpf.Sample/SamplesWpfControls/ColorControls/WellKnownColorPickerView.xaml +++ b/sample/Atc.Wpf.Sample/SamplesWpfControls/ColorControls/WellKnownColorPickerView.xaml @@ -16,22 +16,38 @@ Margin="0,0,0,10" Padding="10" Header="Features"> - - - + + + + + + + + + diff --git a/src/Atc.Wpf.Controls/Adorners/PointPickerAdorner.cs b/src/Atc.Wpf.Controls/Adorners/PointPickerAdorner.cs index 6547e727..118d01da 100644 --- a/src/Atc.Wpf.Controls/Adorners/PointPickerAdorner.cs +++ b/src/Atc.Wpf.Controls/Adorners/PointPickerAdorner.cs @@ -1,23 +1,14 @@ namespace Atc.Wpf.Controls.Adorners; -public sealed class PointPickerAdorner : Adorner +public sealed partial class PointPickerAdorner : Adorner { private static readonly Brush FillBrush = Brushes.Transparent; private readonly Pen selectorPen; - private static readonly DependencyProperty PositionProperty = DependencyProperty.Register( - nameof(Position), - typeof(Point), - typeof(PointPickerAdorner), - new FrameworkPropertyMetadata( - default(Point), - FrameworkPropertyMetadataOptions.AffectsRender)); - - public Point Position - { - get => (Point)GetValue(PositionProperty); - set => SetValue(PositionProperty, value); - } + [DependencyProperty( + DefaultValue = "default(Point)", + Flags = FrameworkPropertyMetadataOptions.AffectsRender)] + private Point position; public PointPickerAdorner( UIElement adornedElement) diff --git a/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj b/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj index 1b423041..57140902 100644 --- a/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj +++ b/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj @@ -48,8 +48,8 @@ - - + + diff --git a/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs index e1dafb6a..9140bb85 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs @@ -21,17 +21,8 @@ public event EventHandler SelectedClockChanged remove => RemoveHandler(SelectedClockChangedEvent, value); } - public static readonly DependencyProperty SelectedDateTimeProperty = DependencyProperty.Register( - nameof(SelectedDateTime), - typeof(DateTime?), - typeof(ClockPanelPicker), - new PropertyMetadata(default(DateTime?))); - - public DateTime? SelectedDateTime - { - get => (DateTime?)GetValue(SelectedDateTimeProperty); - set => SetValue(SelectedDateTimeProperty, value); - } + [DependencyProperty(DefaultValue = "default(DateTime?)")] + private DateTime? selectedDateTime; public ClockPanelPicker() { diff --git a/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs index d6d4b518..76008545 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs @@ -2,32 +2,26 @@ namespace Atc.Wpf.Controls.BaseControls; public partial class ColorPicker { - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(ColorPicker), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; + // Note: DependencyProperty-SourceGenerator don't support "typeof(Color) as null" for now public static readonly DependencyProperty ColorValueProperty = DependencyProperty.Register( nameof(ColorValue), typeof(Color), - typeof(ColorPicker), + typeof(LabelColorPicker), new PropertyMetadata( Colors.Black, OnColorValueChanged)); + // Note: DependencyProperty-SourceGenerator don't support "typeof(Color) as null" for now public Color? ColorValue { get => (Color?)GetValue(ColorValueProperty); set => SetValue(ColorValueProperty, value); } + // Note: DependencyProperty-SourceGenerator don't support "typeof(SolidColorBrush) as null" for now public static readonly DependencyProperty BrushValueProperty = DependencyProperty.Register( nameof(BrushValue), typeof(SolidColorBrush), @@ -36,6 +30,7 @@ public Color? ColorValue Brushes.Black, OnBrushValueChanged)); + // Note: DependencyProperty-SourceGenerator don't support "typeof(SolidColorBrush) as null" for now public SolidColorBrush? BrushValue { get => (SolidColorBrush?)GetValue(BrushValueProperty); diff --git a/src/Atc.Wpf.Controls/ColorControls/WellKnownColorPicker.xaml.cs b/src/Atc.Wpf.Controls/ColorControls/WellKnownColorPicker.xaml.cs index e6a32b15..bf3e2d7e 100644 --- a/src/Atc.Wpf.Controls/ColorControls/WellKnownColorPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/ColorControls/WellKnownColorPicker.xaml.cs @@ -3,32 +3,26 @@ namespace Atc.Wpf.Controls.ColorControls; [SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "OK.")] public partial class WellKnownColorPicker { - public static readonly DependencyProperty ShowOnlyBasicColorsProperty = DependencyProperty.Register( - nameof(ShowOnlyBasicColors), - typeof(bool), - typeof(WellKnownColorPicker), - new PropertyMetadata( - BooleanBoxes.FalseBox, - OnShowOnlyStandardChanged)); - - public bool ShowOnlyBasicColors - { - get => (bool)GetValue(ShowOnlyBasicColorsProperty); - set => SetValue(ShowOnlyBasicColorsProperty, value); - } + [DependencyProperty(DefaultValue = false, PropertyChangedCallback = nameof(OnShowOnlyStandardChanged))] + private bool showOnlyBasicColors; + // Note: DependencyProperty-SourceGenerator don't support "List" for now public static readonly DependencyProperty PaletteProperty = DependencyProperty.Register( nameof(Palette), typeof(List), typeof(WellKnownColorPicker), new PropertyMetadata(default(List))); + // Note: DependencyProperty-SourceGenerator don't support "List" for now public List Palette { get => (List)GetValue(PaletteProperty); set => SetValue(PaletteProperty, value); } + [DependencyProperty(DefaultValue = "Transparent")] + private Brush colorBrush; + public event EventHandler>? ColorChanged; public WellKnownColorPicker() @@ -67,5 +61,7 @@ private void OnPaletteColorClick( ControlHelper.GetIdentifier(this), oldValue: default, color)); + + ColorBrush = new SolidColorBrush(color); } } \ No newline at end of file diff --git a/src/Atc.Wpf.Controls/GlobalUsings.cs b/src/Atc.Wpf.Controls/GlobalUsings.cs index adafe0cb..fe63a0c9 100644 --- a/src/Atc.Wpf.Controls/GlobalUsings.cs +++ b/src/Atc.Wpf.Controls/GlobalUsings.cs @@ -72,6 +72,7 @@ global using Atc.Wpf.Translation; global using Atc.Wpf.ValueConverters; global using Atc.XamlToolkit.Command; +global using Atc.XamlToolkit.Controls.Attributes; global using Atc.XamlToolkit.Messaging; global using Atc.XamlToolkit.Mvvm; diff --git a/src/Atc.Wpf.Controls/LabelControls/Factories/LabelControlFactory.cs b/src/Atc.Wpf.Controls/LabelControls/Factories/LabelControlFactory.cs index 019a88b3..46826329 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Factories/LabelControlFactory.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Factories/LabelControlFactory.cs @@ -782,7 +782,7 @@ public static LabelWellKnownColorSelector CreateLabelWellKnownColorSelector( IsMandatory = isMandatory, InputDataType = inputDataType, DropDownFirstItemType = DropDownFirstItemType.PleaseSelect, - DefaultColorName = defaultColorName, + DefaultColorName = defaultColorName ?? string.Empty, }; return control; @@ -821,7 +821,7 @@ public static LabelCountrySelector CreateLabelCountrySelector( IsMandatory = isMandatory, InputDataType = inputDataType, DropDownFirstItemType = DropDownFirstItemType.PleaseSelect, - DefaultCultureIdentifier = defaultCultureIdentifier, + DefaultCultureIdentifier = defaultCultureIdentifier ?? string.Empty, UseOnlySupportedCountries = false, }; @@ -861,7 +861,7 @@ public static LabelLanguageSelector CreateLabelLanguageSelector( IsMandatory = isMandatory, InputDataType = inputDataType, DropDownFirstItemType = DropDownFirstItemType.PleaseSelect, - DefaultCultureIdentifier = defaultCultureIdentifier, + DefaultCultureIdentifier = defaultCultureIdentifier ?? string.Empty, UseOnlySupportedLanguages = false, UpdateUiCultureOnChangeEvent = false, }; diff --git a/src/Atc.Wpf.Controls/LabelControls/LabelColorPicker.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/LabelColorPicker.xaml.cs index 7692bc40..ba295641 100644 --- a/src/Atc.Wpf.Controls/LabelControls/LabelColorPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/LabelColorPicker.xaml.cs @@ -2,18 +2,10 @@ namespace Atc.Wpf.Controls.LabelControls; public partial class LabelColorPicker : ILabelColorPicker { - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(LabelColorPicker), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; + // Note: DependencyProperty-SourceGenerator don't support "typeof(Color) as null" for now public static readonly DependencyProperty ColorValueProperty = DependencyProperty.Register( nameof(ColorValue), typeof(Color), @@ -22,12 +14,14 @@ public RenderColorIndicatorType RenderColorIndicatorType Colors.Black, OnColorValueChanged)); + // Note: DependencyProperty-SourceGenerator don't support "typeof(Color) as null" for now public Color? ColorValue { get => (Color?)GetValue(ColorValueProperty); set => SetValue(ColorValueProperty, value); } + // Note: DependencyProperty-SourceGenerator don't support "typeof(SolidColorBrush) as null" for now public static readonly DependencyProperty BrushValueProperty = DependencyProperty.Register( nameof(BrushValue), typeof(SolidColorBrush), @@ -36,6 +30,7 @@ public Color? ColorValue Brushes.Black, OnBrushValueChanged)); + // Note: DependencyProperty-SourceGenerator don't support "typeof(SolidColorBrush) as null" for now public SolidColorBrush? BrushValue { get => (SolidColorBrush?)GetValue(BrushValueProperty); diff --git a/src/Atc.Wpf.Controls/LabelControls/LabelComboBox.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/LabelComboBox.xaml.cs index 9b94cd03..d79b4fc9 100644 --- a/src/Atc.Wpf.Controls/LabelControls/LabelComboBox.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/LabelComboBox.xaml.cs @@ -2,18 +2,21 @@ namespace Atc.Wpf.Controls.LabelControls; public partial class LabelComboBox : ILabelComboBox { + // Note: DependencyProperty-SourceGenerator don't support "Dictionary" for now public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register( nameof(Items), typeof(Dictionary), typeof(LabelComboBox), new PropertyMetadata(default(Dictionary))); + // Note: DependencyProperty-SourceGenerator don't support "Dictionary" for now public Dictionary Items { get => (Dictionary)GetValue(ItemsProperty); set => SetValue(ItemsProperty, value); } + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), @@ -26,6 +29,7 @@ public Dictionary Items isAnimationProhibited: true, UpdateSourceTrigger.LostFocus)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelAccentColorSelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelAccentColorSelector.xaml.cs index 97e5aaaf..caffed81 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelAccentColorSelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelAccentColorSelector.xaml.cs @@ -3,17 +3,8 @@ namespace Atc.Wpf.Controls.LabelControls; public partial class LabelAccentColorSelector { - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(LabelAccentColorSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; public LabelAccentColorSelector() { diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelCountrySelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelCountrySelector.xaml.cs index 3ff7d0b7..73292be4 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelCountrySelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelCountrySelector.xaml.cs @@ -4,54 +4,19 @@ namespace Atc.Wpf.Controls.LabelControls; [SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "OK.")] public partial class LabelCountrySelector : ILabelCountrySelector { - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(LabelCountrySelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } - - public static readonly DependencyProperty RenderFlagIndicatorTypeTypeProperty = DependencyProperty.Register( - nameof(RenderFlagIndicatorType), - typeof(RenderFlagIndicatorType), - typeof(LabelCountrySelector), - new PropertyMetadata(RenderFlagIndicatorType.Flat16)); + [DependencyProperty(DefaultValue = RenderFlagIndicatorType.Flat16)] + private RenderFlagIndicatorType renderFlagIndicatorType; - public RenderFlagIndicatorType RenderFlagIndicatorType - { - get => (RenderFlagIndicatorType)GetValue(RenderFlagIndicatorTypeTypeProperty); - set => SetValue(RenderFlagIndicatorTypeTypeProperty, value); - } - - public static readonly DependencyProperty UseOnlySupportedCountriesProperty = DependencyProperty.Register( - nameof(UseOnlySupportedCountries), - typeof(bool), - typeof(LabelCountrySelector), - new PropertyMetadata(defaultValue: true)); + [DependencyProperty(DefaultValue = true)] + private bool useOnlySupportedCountries; - public bool UseOnlySupportedCountries - { - get => (bool)GetValue(UseOnlySupportedCountriesProperty); - set => SetValue(UseOnlySupportedCountriesProperty, value); - } - - public static readonly DependencyProperty DefaultCultureIdentifierProperty = DependencyProperty.Register( - nameof(DefaultCultureIdentifier), - typeof(string), - typeof(LabelCountrySelector), - new PropertyMetadata(null)); - - public string? DefaultCultureIdentifier - { - get => (string?)GetValue(DefaultCultureIdentifierProperty); - set => SetValue(DefaultCultureIdentifierProperty, value); - } + [DependencyProperty] + private string defaultCultureIdentifier; + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), @@ -64,6 +29,7 @@ public string? DefaultCultureIdentifier isAnimationProhibited: true, UpdateSourceTrigger.LostFocus)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelFontFamilySelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelFontFamilySelector.xaml.cs index 24337647..b4f9ff6a 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelFontFamilySelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelFontFamilySelector.xaml.cs @@ -4,18 +4,10 @@ namespace Atc.Wpf.Controls.LabelControls; [SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "OK.")] public partial class LabelFontFamilySelector : ILabelFontFamilySelector { - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(LabelFontFamilySelector), - new PropertyMetadata(DropDownFirstItemType.None)); - - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), @@ -28,6 +20,7 @@ public DropDownFirstItemType DropDownFirstItemType isAnimationProhibited: true, UpdateSourceTrigger.LostFocus)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelLanguageSelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelLanguageSelector.xaml.cs index 3ace8de9..efa02ab2 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelLanguageSelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelLanguageSelector.xaml.cs @@ -5,54 +5,19 @@ namespace Atc.Wpf.Controls.LabelControls; [SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "OK.")] public partial class LabelLanguageSelector : ILabelLanguageSelector { - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(LabelLanguageSelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderFlagIndicatorType.Flat16)] + private RenderFlagIndicatorType renderFlagIndicatorType; - public static readonly DependencyProperty RenderFlagIndicatorTypeTypeProperty = DependencyProperty.Register( - nameof(RenderFlagIndicatorType), - typeof(RenderFlagIndicatorType), - typeof(LabelLanguageSelector), - new PropertyMetadata(RenderFlagIndicatorType.Flat16)); + [DependencyProperty(DefaultValue = true)] + private bool useOnlySupportedLanguages; - public RenderFlagIndicatorType RenderFlagIndicatorType - { - get => (RenderFlagIndicatorType)GetValue(RenderFlagIndicatorTypeTypeProperty); - set => SetValue(RenderFlagIndicatorTypeTypeProperty, value); - } - - public static readonly DependencyProperty UseOnlySupportedLanguagesProperty = DependencyProperty.Register( - nameof(UseOnlySupportedLanguages), - typeof(bool), - typeof(LabelLanguageSelector), - new PropertyMetadata(defaultValue: true)); - - public bool UseOnlySupportedLanguages - { - get => (bool)GetValue(UseOnlySupportedLanguagesProperty); - set => SetValue(UseOnlySupportedLanguagesProperty, value); - } - - public static readonly DependencyProperty DefaultCultureIdentifierProperty = DependencyProperty.Register( - nameof(DefaultCultureIdentifier), - typeof(string), - typeof(LabelLanguageSelector), - new PropertyMetadata(default)); - - public string? DefaultCultureIdentifier - { - get => (string?)GetValue(DefaultCultureIdentifierProperty); - set => SetValue(DefaultCultureIdentifierProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string defaultCultureIdentifier; + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), @@ -63,25 +28,17 @@ public string? DefaultCultureIdentifier OnSelectorLostFocus, coerceValueCallback: null, isAnimationProhibited: true, - UpdateSourceTrigger.LostFocus)); + defaultUpdateSourceTrigger: UpdateSourceTrigger.LostFocus)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); set => SetValue(SelectedKeyProperty, value); } - public static readonly DependencyProperty UpdateUiCultureOnChangeEventProperty = DependencyProperty.Register( - nameof(UpdateUiCultureOnChangeEvent), - typeof(bool), - typeof(LabelLanguageSelector), - new PropertyMetadata(defaultValue: true)); - - public bool UpdateUiCultureOnChangeEvent - { - get => (bool)GetValue(UpdateUiCultureOnChangeEventProperty); - set => SetValue(UpdateUiCultureOnChangeEventProperty, value); - } + [DependencyProperty(DefaultValue = true)] + private bool updateUiCultureOnChangeEvent; public event EventHandler>? SelectorChanged; diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeAndAccentColorSelectors.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeAndAccentColorSelectors.xaml.cs index c2f57b05..a425489c 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeAndAccentColorSelectors.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeAndAccentColorSelectors.xaml.cs @@ -3,29 +3,11 @@ namespace Atc.Wpf.Controls.LabelControls; public partial class LabelThemeAndAccentColorSelectors { - public static readonly DependencyProperty LabelControlOrientationProperty = DependencyProperty.Register( - nameof(LabelControlOrientation), - typeof(Orientation), - typeof(LabelThemeAndAccentColorSelectors), - new PropertyMetadata(default(Orientation))); + [DependencyProperty(DefaultValue = Orientation.Horizontal)] + private Orientation labelControlOrientation; - public Orientation LabelControlOrientation - { - get => (Orientation)GetValue(LabelControlOrientationProperty); - set => SetValue(LabelControlOrientationProperty, value); - } - - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(LabelThemeAndAccentColorSelectors), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; public LabelThemeAndAccentColorSelectors() { diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeSelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeSelector.xaml.cs index 421c43b4..d2acbff1 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeSelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelThemeSelector.xaml.cs @@ -3,17 +3,8 @@ namespace Atc.Wpf.Controls.LabelControls; public partial class LabelThemeSelector { - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(LabelThemeSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; public LabelThemeSelector() { diff --git a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelWellKnownColorSelector.xaml.cs b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelWellKnownColorSelector.xaml.cs index a472080a..293db05f 100644 --- a/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelWellKnownColorSelector.xaml.cs +++ b/src/Atc.Wpf.Controls/LabelControls/Selectors/LabelWellKnownColorSelector.xaml.cs @@ -7,78 +7,35 @@ public partial class LabelWellKnownColorSelector : ILabelWellKnownColorSelector private bool isFirstOnSelectedKeyLostFocus; private string? lastSelectedKey; - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(LabelWellKnownColorSelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(LabelWellKnownColorSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); + [DependencyProperty(DefaultValue = false)] + private bool showHexCode; - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } - - public static readonly DependencyProperty ShowHexCodeProperty = DependencyProperty.Register( - nameof(ShowHexCode), - typeof(bool), - typeof(LabelWellKnownColorSelector), - new PropertyMetadata(defaultValue: BooleanBoxes.FalseBox)); - - public bool ShowHexCode - { - get => (bool)GetValue(ShowHexCodeProperty); - set => SetValue(ShowHexCodeProperty, value); - } + [DependencyProperty(DefaultValue = false)] + private bool useOnlyBasicColors; - public static readonly DependencyProperty UseOnlyBasicColorsProperty = DependencyProperty.Register( - nameof(UseOnlyBasicColors), - typeof(bool), - typeof(LabelWellKnownColorSelector), - new PropertyMetadata(defaultValue: false)); - - public bool UseOnlyBasicColors - { - get => (bool)GetValue(UseOnlyBasicColorsProperty); - set => SetValue(UseOnlyBasicColorsProperty, value); - } - - public static readonly DependencyProperty DefaultColorNameProperty = DependencyProperty.Register( - nameof(DefaultColorName), - typeof(string), - typeof(LabelWellKnownColorSelector), - new PropertyMetadata(default)); - - public string? DefaultColorName - { - get => (string?)GetValue(DefaultColorNameProperty); - set => SetValue(DefaultColorNameProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string defaultColorName; + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), typeof(LabelWellKnownColorSelector), new FrameworkPropertyMetadata( - default(string), + defaultValue: string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, OnSelectedKeyLostFocus, coerceValueCallback: null, isAnimationProhibited: true, UpdateSourceTrigger.LostFocus)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); diff --git a/src/Atc.Wpf.Theming/Controls/Selectors/AccentColorSelector.xaml.cs b/src/Atc.Wpf.Theming/Controls/Selectors/AccentColorSelector.xaml.cs index e8beaa9f..898ee6d5 100644 --- a/src/Atc.Wpf.Theming/Controls/Selectors/AccentColorSelector.xaml.cs +++ b/src/Atc.Wpf.Theming/Controls/Selectors/AccentColorSelector.xaml.cs @@ -5,17 +5,8 @@ public partial class AccentColorSelector : INotifyPropertyChanged { private string selectedKey = string.Empty; - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(AccentColorSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; public AccentColorSelector() { diff --git a/src/Atc.Wpf.Theming/Controls/Selectors/ThemeSelector.xaml.cs b/src/Atc.Wpf.Theming/Controls/Selectors/ThemeSelector.xaml.cs index b7b4636e..e34b869c 100644 --- a/src/Atc.Wpf.Theming/Controls/Selectors/ThemeSelector.xaml.cs +++ b/src/Atc.Wpf.Theming/Controls/Selectors/ThemeSelector.xaml.cs @@ -4,17 +4,8 @@ public partial class ThemeSelector : INotifyPropertyChanged { private string selectedKey = string.Empty; - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(ThemeSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); - - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; public ThemeSelector() { diff --git a/src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml.cs b/src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml.cs index c2c73c4e..2e387ee2 100644 --- a/src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml.cs +++ b/src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml.cs @@ -9,66 +9,22 @@ public partial class WellKnownColorSelector private string? lastName; private bool processingUiCultureChanged; - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(WellKnownColorSelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } + [DependencyProperty(DefaultValue = RenderColorIndicatorType.Square)] + private RenderColorIndicatorType renderColorIndicatorType; - public static readonly DependencyProperty RenderColorIndicatorTypeProperty = DependencyProperty.Register( - nameof(RenderColorIndicatorType), - typeof(RenderColorIndicatorType), - typeof(WellKnownColorSelector), - new PropertyMetadata(RenderColorIndicatorType.Square)); + [DependencyProperty(DefaultValue = true)] + private bool showHexCode; - public RenderColorIndicatorType RenderColorIndicatorType - { - get => (RenderColorIndicatorType)GetValue(RenderColorIndicatorTypeProperty); - set => SetValue(RenderColorIndicatorTypeProperty, value); - } - - public static readonly DependencyProperty ShowHexCodeProperty = DependencyProperty.Register( - nameof(ShowHexCode), - typeof(bool), - typeof(WellKnownColorSelector), - new PropertyMetadata(defaultValue: BooleanBoxes.TrueBox)); - - public bool ShowHexCode - { - get => (bool)GetValue(ShowHexCodeProperty); - set => SetValue(ShowHexCodeProperty, value); - } + [DependencyProperty(DefaultValue = false)] + private bool useOnlyBasicColors; - public static readonly DependencyProperty UseOnlyBasicColorsProperty = DependencyProperty.Register( - nameof(UseOnlyBasicColors), - typeof(bool), - typeof(WellKnownColorSelector), - new PropertyMetadata(defaultValue: false)); - - public bool UseOnlyBasicColors - { - get => (bool)GetValue(UseOnlyBasicColorsProperty); - set => SetValue(UseOnlyBasicColorsProperty, value); - } - - public static readonly DependencyProperty DefaultColorNameProperty = DependencyProperty.Register( - nameof(DefaultColorName), - typeof(string), - typeof(WellKnownColorSelector), - new PropertyMetadata(default)); - - public string? DefaultColorName - { - get => (string?)GetValue(DefaultColorNameProperty); - set => SetValue(DefaultColorNameProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string defaultColorName; + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( nameof(SelectedKey), typeof(string), @@ -77,6 +33,7 @@ public string? DefaultColorName string.Empty, OnSelectedKeyChanged)); + // Note: DependencyProperty-SourceGenerator don't support "coerceValueCallback / isAnimationProhibited" correctly for now public string SelectedKey { get => (string)GetValue(SelectedKeyProperty); diff --git a/src/Atc.Wpf.Theming/GlobalUsings.cs b/src/Atc.Wpf.Theming/GlobalUsings.cs index dec3ff92..0d023cf2 100644 --- a/src/Atc.Wpf.Theming/GlobalUsings.cs +++ b/src/Atc.Wpf.Theming/GlobalUsings.cs @@ -54,4 +54,5 @@ global using Windows.Win32; global using Windows.Win32.Foundation; global using Windows.Win32.Graphics.Gdi; -global using Windows.Win32.UI.WindowsAndMessaging; \ No newline at end of file +global using Windows.Win32.UI.WindowsAndMessaging; +global using Atc.XamlToolkit.Controls.Attributes; \ No newline at end of file diff --git a/src/Atc.Wpf/Atc.Wpf.csproj b/src/Atc.Wpf/Atc.Wpf.csproj index 3b1de635..0e2052fc 100644 --- a/src/Atc.Wpf/Atc.Wpf.csproj +++ b/src/Atc.Wpf/Atc.Wpf.csproj @@ -1014,8 +1014,8 @@ - - + + diff --git a/src/Atc.Wpf/Controls/Layouts/ReversibleStackPanel.cs b/src/Atc.Wpf/Controls/Layouts/ReversibleStackPanel.cs index a9182b32..9507f8f2 100644 --- a/src/Atc.Wpf/Controls/Layouts/ReversibleStackPanel.cs +++ b/src/Atc.Wpf/Controls/Layouts/ReversibleStackPanel.cs @@ -1,18 +1,9 @@ namespace Atc.Wpf.Controls.Layouts; -public sealed class ReversibleStackPanel : StackPanel +public sealed partial class ReversibleStackPanel : StackPanel { - public static readonly DependencyProperty ReverseOrderProperty = DependencyProperty.Register( - nameof(ReverseOrder), - typeof(bool), - typeof(ReversibleStackPanel), - new PropertyMetadata(defaultValue: false)); - - public bool ReverseOrder - { - get => (bool)GetValue(ReverseOrderProperty); - set => SetValue(ReverseOrderProperty, value); - } + [DependencyProperty] + private bool reverseOrder; protected override Size ArrangeOverride( Size arrangeSize) diff --git a/src/Atc.Wpf/Controls/Layouts/StaggeredPanel.cs b/src/Atc.Wpf/Controls/Layouts/StaggeredPanel.cs index 3439df07..ab9d9f5e 100644 --- a/src/Atc.Wpf/Controls/Layouts/StaggeredPanel.cs +++ b/src/Atc.Wpf/Controls/Layouts/StaggeredPanel.cs @@ -2,65 +2,37 @@ // ReSharper disable SwitchStatementMissingSomeEnumCasesNoDefault namespace Atc.Wpf.Controls.Layouts; -public sealed class StaggeredPanel : Panel +public sealed partial class StaggeredPanel : Panel { private const int ArrayMaxItems = 10_000; private double itemWidth; - public static readonly DependencyProperty DesiredItemWidthProperty = DependencyProperty.Register( - nameof(DesiredItemWidth), - typeof(double), - typeof(StaggeredPanel), - new PropertyMetadata( - 250d, - (sender, _) => ((StaggeredPanel)sender).InvalidateMeasure())); + [DependencyProperty( + DefaultValue = 250d, + PropertyChangedCallback = nameof(OnInvalidateMeasure))] + private double desiredItemWidth; - public double DesiredItemWidth - { - get => (double)GetValue(DesiredItemWidthProperty); - set => SetValue(DesiredItemWidthProperty, value); - } - - public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register( - nameof(Padding), - typeof(Thickness), - typeof(StaggeredPanel), - new PropertyMetadata( - default(Thickness), - (sender, _) => ((StaggeredPanel)sender).InvalidateMeasure())); + [DependencyProperty( + DefaultValue = "default(Thickness)", + PropertyChangedCallback = nameof(OnInvalidateMeasure))] + private Thickness padding; - public Thickness Padding - { - get => (Thickness)GetValue(PaddingProperty); - set => SetValue(PaddingProperty, value); - } + [DependencyProperty( + DefaultValue = 0d, + PropertyChangedCallback = nameof(OnInvalidateMeasure))] + private double horizontalSpacing; - public static readonly DependencyProperty HorizontalSpacingProperty = DependencyProperty.Register( - nameof(HorizontalSpacing), - typeof(double), - typeof(StaggeredPanel), - new PropertyMetadata( - 0d, - (sender, _) => ((StaggeredPanel)sender).InvalidateMeasure())); + [DependencyProperty( + DefaultValue = 0d, + PropertyChangedCallback = nameof(OnInvalidateMeasure))] + private double verticalSpacing; - public double HorizontalSpacing - { - get => (double)GetValue(HorizontalSpacingProperty); - set => SetValue(HorizontalSpacingProperty, value); - } - - public static readonly DependencyProperty VerticalSpacingProperty = DependencyProperty.Register( - nameof(VerticalSpacing), - typeof(double), - typeof(StaggeredPanel), - new PropertyMetadata( - 0d, - (sender, _) => ((StaggeredPanel)sender).InvalidateMeasure())); - - public double VerticalSpacing + private static void OnInvalidateMeasure( + DependencyObject d, + DependencyPropertyChangedEventArgs e) { - get => (double)GetValue(VerticalSpacingProperty); - set => SetValue(VerticalSpacingProperty, value); + var staggeredPanel = (StaggeredPanel)d; + staggeredPanel.InvalidateMeasure(); } static StaggeredPanel() diff --git a/src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel.cs b/src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel.cs index abe4872b..6139f17f 100644 --- a/src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel.cs +++ b/src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel.cs @@ -1,16 +1,59 @@ +// ReSharper disable LocalVariableHidesMember namespace Atc.Wpf.Controls.Layouts; [SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")] -public sealed class UniformSpacingPanel : Panel +public sealed partial class UniformSpacingPanel : Panel { - private Orientation orientation = Orientation.Horizontal; - - public static readonly DependencyProperty OrientationProperty = StackPanel.OrientationProperty.AddOwner( - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - Orientation.Horizontal, - FrameworkPropertyMetadataOptions.AffectsMeasure, - OnOrientationChanged)); + [DependencyProperty( + DefaultValue = Orientation.Horizontal, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(OnOrientationChanged))] + private Orientation orientation; + + [DependencyProperty( + DefaultValue = default(VisualWrappingType), + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure)] + private VisualWrappingType childWrapping; + + [DependencyProperty( + DefaultValue = double.NaN, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + ValidateValueCallback = nameof(IsSpacingValid))] + private double spacing; + + [DependencyProperty( + DefaultValue = double.NaN, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + ValidateValueCallback = nameof(IsSpacingValid))] + private double horizontalSpacing; + + [DependencyProperty( + DefaultValue = double.NaN, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + ValidateValueCallback = nameof(IsSpacingValid))] + private double verticalSpacing; + + [DependencyProperty( + DefaultValue = double.NaN, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + ValidateValueCallback = nameof(IsWidthHeightValid))] + private double itemWidth; + + [DependencyProperty( + DefaultValue = double.NaN, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + ValidateValueCallback = nameof(IsWidthHeightValid))] + private double itemHeight; + + [DependencyProperty( + DefaultValue = HorizontalAlignment.Stretch, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure)] + private HorizontalAlignment? itemHorizontalAlignment; + + [DependencyProperty( + DefaultValue = VerticalAlignment.Stretch, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure)] + private VerticalAlignment? itemVerticalAlignment; private static void OnOrientationChanged( DependencyObject d, @@ -20,131 +63,6 @@ private static void OnOrientationChanged( p.orientation = (Orientation)e.NewValue; } - public Orientation Orientation - { - get => (Orientation)GetValue(OrientationProperty); - set => SetValue(OrientationProperty, value); - } - - public static readonly DependencyProperty ChildWrappingProperty = DependencyProperty.Register( - nameof(ChildWrapping), - typeof(VisualWrappingType), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - default(VisualWrappingType), - FrameworkPropertyMetadataOptions.AffectsMeasure)); - - public VisualWrappingType ChildWrapping - { - get => (VisualWrappingType)GetValue(ChildWrappingProperty); - set => SetValue(ChildWrappingProperty, value); - } - - public static readonly DependencyProperty SpacingProperty = DependencyProperty.Register( - nameof(Spacing), - typeof(double), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - double.NaN, - FrameworkPropertyMetadataOptions.AffectsMeasure), - IsSpacingValid); - - public double Spacing - { - get => (double)GetValue(SpacingProperty); - set => SetValue(SpacingProperty, value); - } - - public static readonly DependencyProperty HorizontalSpacingProperty = DependencyProperty.Register( - nameof(HorizontalSpacing), - typeof(double), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - double.NaN, - FrameworkPropertyMetadataOptions.AffectsMeasure), - IsSpacingValid); - - public double HorizontalSpacing - { - get => (double)GetValue(HorizontalSpacingProperty); - set => SetValue(HorizontalSpacingProperty, value); - } - - public static readonly DependencyProperty VerticalSpacingProperty = DependencyProperty.Register( - nameof(VerticalSpacing), - typeof(double), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - double.NaN, - FrameworkPropertyMetadataOptions.AffectsMeasure), - IsSpacingValid); - - public double VerticalSpacing - { - get => (double)GetValue(VerticalSpacingProperty); - set => SetValue(VerticalSpacingProperty, value); - } - - public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register( - nameof(ItemWidth), - typeof(double), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - double.NaN, - FrameworkPropertyMetadataOptions.AffectsMeasure), - IsWidthHeightValid); - - [TypeConverter(typeof(LengthConverter))] - public double ItemWidth - { - get => (double)GetValue(ItemWidthProperty); - set => SetValue(ItemWidthProperty, value); - } - - public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register( - nameof(ItemHeight), - typeof(double), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - double.NaN, - FrameworkPropertyMetadataOptions.AffectsMeasure), - IsWidthHeightValid); - - [TypeConverter(typeof(LengthConverter))] - public double ItemHeight - { - get => (double)GetValue(ItemHeightProperty); - set => SetValue(ItemHeightProperty, value); - } - - public static readonly DependencyProperty ItemHorizontalAlignmentProperty = DependencyProperty.Register( - nameof(ItemHorizontalAlignment), - typeof(HorizontalAlignment?), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - HorizontalAlignment.Stretch, - FrameworkPropertyMetadataOptions.AffectsMeasure)); - - public HorizontalAlignment? ItemHorizontalAlignment - { - get => (HorizontalAlignment?)GetValue(ItemHorizontalAlignmentProperty); - set => SetValue(ItemHorizontalAlignmentProperty, value); - } - - public static readonly DependencyProperty ItemVerticalAlignmentProperty = DependencyProperty.Register( - nameof(ItemVerticalAlignment), - typeof(VerticalAlignment?), - typeof(UniformSpacingPanel), - new FrameworkPropertyMetadata( - VerticalAlignment.Stretch, - FrameworkPropertyMetadataOptions.AffectsMeasure)); - - public VerticalAlignment? ItemVerticalAlignment - { - get => (VerticalAlignment?)GetValue(ItemVerticalAlignmentProperty); - set => SetValue(ItemVerticalAlignmentProperty, value); - } - private static bool IsWidthHeightValid( object value) { @@ -163,7 +81,7 @@ private void ArrangeWrapLine( int end, bool useItemU, double itemU, - double spacing) + double space) { double u = 0; var isHorizontal = orientation == Orientation.Horizontal; @@ -188,7 +106,7 @@ private void ArrangeWrapLine( if (layoutSlotU > 0) { - u += layoutSlotU + spacing; + u += layoutSlotU + space; } } } @@ -197,7 +115,7 @@ private void ArrangeLine( double lineV, bool useItemU, double itemU, - double spacing) + double space) { double u = 0; var isHorizontal = orientation == Orientation.Horizontal; @@ -222,36 +140,35 @@ private void ArrangeLine( if (layoutSlotU > 0) { - u += layoutSlotU + spacing; + u += layoutSlotU + space; } } } + [SuppressMessage("", "MA0084:Local variable should not hide field", Justification = "OK.")] + [SuppressMessage("", "S1117:Local variable should not hide field", Justification = "OK.")] protected override Size MeasureOverride( Size availableSize) { var curLineSize = new PanelUvSize(orientation); var panelSize = new PanelUvSize(orientation); var uvConstraint = new PanelUvSize(orientation, availableSize); - var itemWidth = ItemWidth; - var itemHeight = ItemHeight; - var itemWidthSet = !double.IsNaN(itemWidth); - var itemHeightSet = !double.IsNaN(itemHeight); - var childWrapping = ChildWrapping; + var itemWidthSet = !double.IsNaN(ItemWidth); + var itemHeightSet = !double.IsNaN(ItemHeight); var itemHorizontalAlignment = ItemHorizontalAlignment; var itemVerticalAlignment = ItemVerticalAlignment; - var itemHorizontalAlignmentSet = itemHorizontalAlignment != null; - var itemVerticalAlignmentSet = ItemVerticalAlignment != null; + var itemHorizontalAlignmentSet = itemHorizontalAlignment is not null; + var itemVerticalAlignmentSet = itemVerticalAlignment is not null; var spacingSize = GetSpacingSize(); var childConstraint = new Size( - itemWidthSet ? itemWidth : availableSize.Width, - itemHeightSet ? itemHeight : availableSize.Height); + itemWidthSet ? ItemWidth : availableSize.Width, + itemHeightSet ? ItemHeight : availableSize.Height); var children = InternalChildren; var isFirst = true; - if (childWrapping == VisualWrappingType.Wrap) + if (ChildWrapping == VisualWrappingType.Wrap) { for (int i = 0, count = children.Count; i < count; i++) { @@ -263,20 +180,20 @@ protected override Size MeasureOverride( if (itemHorizontalAlignmentSet) { - child.SetCurrentValue(HorizontalAlignmentProperty, itemHorizontalAlignment); + child.SetCurrentValue(HorizontalAlignmentProperty, ItemHorizontalAlignment); } if (itemVerticalAlignmentSet) { - child.SetCurrentValue(VerticalAlignmentProperty, itemVerticalAlignment); + child.SetCurrentValue(VerticalAlignmentProperty, ItemVerticalAlignment); } child.Measure(childConstraint); var sz = new PanelUvSize( orientation, - itemWidthSet ? itemWidth : child.DesiredSize.Width, - itemHeightSet ? itemHeight : child.DesiredSize.Height); + itemWidthSet ? ItemWidth : child.DesiredSize.Width, + itemHeightSet ? ItemHeight : child.DesiredSize.Height); if (GreaterThan(curLineSize.U + sz.U + spacingSize.U, uvConstraint.U)) { @@ -355,22 +272,23 @@ protected override Size ArrangeOverride( Size finalSize) { var firstInLine = 0; - var itemWidth = ItemWidth; - var itemHeight = ItemHeight; double accumulatedV = 0; - var itemU = orientation == Orientation.Horizontal ? itemWidth : itemHeight; + var itemU = orientation == Orientation.Horizontal + ? ItemWidth + : ItemHeight; var curLineSize = new PanelUvSize(orientation); var uvFinalSize = new PanelUvSize(orientation, finalSize); - var itemWidthSet = !double.IsNaN(itemWidth); - var itemHeightSet = !double.IsNaN(itemHeight); - var useItemU = orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet; - var childWrapping = ChildWrapping; + var itemWidthSet = !double.IsNaN(ItemWidth); + var itemHeightSet = !double.IsNaN(ItemHeight); + var useItemU = orientation == Orientation.Horizontal + ? itemWidthSet + : itemHeightSet; var spacingSize = GetSpacingSize(); var children = InternalChildren; var isFirst = true; - if (childWrapping == VisualWrappingType.Wrap) + if (ChildWrapping == VisualWrappingType.Wrap) { for (int i = 0, count = children.Count; i < count; i++) { @@ -382,8 +300,8 @@ protected override Size ArrangeOverride( var sz = new PanelUvSize( orientation, - itemWidthSet ? itemWidth : child.DesiredSize.Width, - itemHeightSet ? itemHeight : child.DesiredSize.Height); + itemWidthSet ? ItemWidth : child.DesiredSize.Width, + itemHeightSet ? ItemHeight : child.DesiredSize.Height); if (GreaterThan(curLineSize.U + (isFirst ? sz.U : sz.U + spacingSize.U), uvFinalSize.U)) { @@ -420,26 +338,22 @@ protected override Size ArrangeOverride( private PanelUvSize GetSpacingSize() { - var spacing = Spacing; - - if (!double.IsNaN(spacing)) + if (!double.IsNaN(Spacing)) { - return new PanelUvSize(orientation, spacing, spacing); + return new PanelUvSize(orientation, Spacing, Spacing); } - var horizontalSpacing = HorizontalSpacing; - if (double.IsNaN(horizontalSpacing)) + if (double.IsNaN(HorizontalSpacing)) { - horizontalSpacing = 0; + HorizontalSpacing = 0; } - var verticalSpacing = VerticalSpacing; - if (double.IsNaN(verticalSpacing)) + if (double.IsNaN(VerticalSpacing)) { - verticalSpacing = 0; + VerticalSpacing = 0; } - return new PanelUvSize(orientation, horizontalSpacing, verticalSpacing); + return new PanelUvSize(orientation, HorizontalSpacing, VerticalSpacing); } private static bool GreaterThan( diff --git a/src/Atc.Wpf/Controls/Media/SvgImage.cs b/src/Atc.Wpf/Controls/Media/SvgImage.cs index 1de9ee4b..f266d6d4 100644 --- a/src/Atc.Wpf/Controls/Media/SvgImage.cs +++ b/src/Atc.Wpf/Controls/Media/SvgImage.cs @@ -11,7 +11,7 @@ namespace Atc.Wpf.Controls.Media; /// multiple controls to share the same drawing instance. /// [SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "OK.")] -public sealed class SvgImage : Control +public sealed partial class SvgImage : Control { private readonly TranslateTransform translateTransform = new(); private readonly ScaleTransform scaleTransform = new(); @@ -19,89 +19,79 @@ public sealed class SvgImage : Control private SvgRender? svgRender; private Action? loadImage; + // Note: DependencyProperty-SourceGenerator don't support "new Brush? Background" for now private static new readonly DependencyProperty BackgroundProperty = DependencyProperty.Register( nameof(Background), typeof(Brush), typeof(SvgImage), new FrameworkPropertyMetadata( - null, + defaultValue: null, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnBackgroundChanged)); - private static readonly DependencyProperty ControlSizeTypeProperty = DependencyProperty.Register( - nameof(ControlSizeType), - typeof(ControlSizeType), - typeof(SvgImage), - new FrameworkPropertyMetadata( - ControlSizeType.ContentToSizeNoStretch, - FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, - OnControlSizeTypeChanged)); + // Note: DependencyProperty-SourceGenerator don't support "new Brush? Background" for now + public new Brush? Background + { + get => (Brush)GetValue(BackgroundProperty); + set => SetValue(BackgroundProperty, value); + } - private static readonly DependencyProperty SourceProperty = DependencyProperty.Register( - nameof(Source), - typeof(string), - typeof(SvgImage), - new FrameworkPropertyMetadata( - defaultValue: null, - FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, - OnSourceChanged)); + [DependencyProperty( + DefaultValue = ControlSizeType.ContentToSizeNoStretch, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, + PropertyChangedCallback = nameof(OnControlSizeTypeChanged))] + private ControlSizeType controlSizeType; - private static readonly DependencyProperty FileSourceProperty = DependencyProperty.Register( - nameof(FileSource), - typeof(string), - typeof(SvgImage), - new PropertyMetadata(OnFileSourceChanged)); + [DependencyProperty( + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, + PropertyChangedCallback = nameof(OnSourceChanged))] + private string source; - private static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register( - nameof(ImageSource), - typeof(Drawing), - typeof(SvgImage), - new FrameworkPropertyMetadata( - defaultValue: null, - FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, - OnImageSourceChanged)); + [DependencyProperty( + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, + PropertyChangedCallback = nameof(OnFileSourceChanged))] + private string fileSource; - private static readonly DependencyProperty UseAnimationsProperty = DependencyProperty.Register( - nameof(UseAnimations), - typeof(bool), - typeof(SvgImage), - new PropertyMetadata(defaultValue: true)); + [DependencyProperty( + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, + PropertyChangedCallback = nameof(OnImageSourceChanged))] + private Drawing imageSource; - private static readonly DependencyProperty OverrideColorProperty = DependencyProperty.Register( - nameof(OverrideColor), - typeof(Color?), - typeof(SvgImage), - new PropertyMetadata(propertyChangedCallback: null)); + [DependencyProperty( + DefaultValue = true)] + private bool useAnimations; - private static readonly DependencyProperty OverrideStrokeColorProperty = DependencyProperty.Register( - nameof(OverrideStrokeColor), - typeof(Color?), - typeof(SvgImage), - new PropertyMetadata(propertyChangedCallback: null)); + [DependencyProperty] + private Color? overrideColor; - private static readonly DependencyProperty OverrideStrokeWidthProperty = DependencyProperty.Register( - nameof(OverrideStrokeWidth), - typeof(double?), - typeof(SvgImage), - new FrameworkPropertyMetadata( - null, - FrameworkPropertyMetadataOptions.AffectsRender, - OverrideStrokeWidthPropertyChanged)); + [DependencyProperty] + private Color? overrideStrokeColor; + + [DependencyProperty( + Flags = FrameworkPropertyMetadataOptions.AffectsRender, + PropertyChangedCallback = nameof(OverrideStrokeWidthPropertyChanged))] + private double? overrideStrokeWidth; + // Note: DependencyProperty-SourceGenerator don't support "Dictionary" for now public static readonly DependencyProperty CustomBrushesProperty = DependencyProperty.Register( nameof(CustomBrushes), typeof(Dictionary), typeof(SvgImage), new FrameworkPropertyMetadata( - null, + defaultValue: null, FrameworkPropertyMetadataOptions.AffectsRender, CustomBrushesPropertyChanged)); - public static readonly DependencyProperty ExternalFileLoaderProperty = DependencyProperty.Register( - nameof(ExternalFileLoader), - typeof(IExternalFileLoader), - typeof(SvgImage), - new PropertyMetadata(FileSystemLoader.Instance)); + // Note: DependencyProperty-SourceGenerator don't support "Dictionary" for now + public Dictionary CustomBrushes + { + get => (Dictionary)GetValue(CustomBrushesProperty); + set => SetValue(CustomBrushesProperty, value); + } + + [DependencyProperty( + DefaultValue = "FileSystemLoader.Instance")] + private IExternalFileLoader externalFileLoader; static SvgImage() { @@ -122,72 +112,6 @@ public SvgImage() SnapsToDevicePixels = true; } - public new Brush? Background - { - get => (Brush)GetValue(BackgroundProperty); - set => SetValue(BackgroundProperty, value); - } - - public ControlSizeType ControlSizeType - { - get => (ControlSizeType)GetValue(ControlSizeTypeProperty); - set => SetValue(ControlSizeTypeProperty, value); - } - - public string Source - { - get => (string)GetValue(SourceProperty); - set => SetValue(SourceProperty, value); - } - - public string FileSource - { - get => (string)GetValue(FileSourceProperty); - set => SetValue(FileSourceProperty, value); - } - - public Drawing ImageSource - { - get => (Drawing)GetValue(ImageSourceProperty); - set => SetValue(ImageSourceProperty, value); - } - - public bool UseAnimations - { - get => (bool)GetValue(UseAnimationsProperty); - set => SetValue(UseAnimationsProperty, value); - } - - public Color? OverrideColor - { - get => (Color?)GetValue(OverrideColorProperty); - set => SetValue(OverrideColorProperty, value); - } - - public Color? OverrideStrokeColor - { - get => (Color?)GetValue(OverrideStrokeColorProperty); - set => SetValue(OverrideStrokeColorProperty, value); - } - - public double? OverrideStrokeWidth - { - get => (double?)GetValue(OverrideStrokeWidthProperty); - set => SetValue(OverrideStrokeWidthProperty, value); - } - - public Dictionary CustomBrushes - { - get => (Dictionary)GetValue(CustomBrushesProperty); - set => SetValue(CustomBrushesProperty, value); - } - - public IExternalFileLoader ExternalFileLoader - { - get => (IExternalFileLoader)GetValue(ExternalFileLoaderProperty); - set => SetValue(ExternalFileLoaderProperty, value); - } - internal Svg? Svg => svgRender?.Svg; public void ReRenderSvg() diff --git a/src/Atc.Wpf/Controls/Selectors/CountrySelector.xaml.cs b/src/Atc.Wpf/Controls/Selectors/CountrySelector.xaml.cs index 9703440c..ce3ba568 100644 --- a/src/Atc.Wpf/Controls/Selectors/CountrySelector.xaml.cs +++ b/src/Atc.Wpf/Controls/Selectors/CountrySelector.xaml.cs @@ -12,79 +12,23 @@ public partial class CountrySelector private int? lastLcid; private bool processingUiCultureChanged; - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(CountrySelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } - - public static readonly DependencyProperty RenderFlagIndicatorTypeTypeProperty = DependencyProperty.Register( - nameof(RenderFlagIndicatorType), - typeof(RenderFlagIndicatorType), - typeof(CountrySelector), - new PropertyMetadata(RenderFlagIndicatorType.Flat16)); - - public RenderFlagIndicatorType RenderFlagIndicatorType - { - get => (RenderFlagIndicatorType)GetValue(RenderFlagIndicatorTypeTypeProperty); - set => SetValue(RenderFlagIndicatorTypeTypeProperty, value); - } - - public static readonly DependencyProperty UseOnlySupportedCountriesProperty = DependencyProperty.Register( - nameof(UseOnlySupportedCountries), - typeof(bool), - typeof(CountrySelector), - new PropertyMetadata(defaultValue: true)); - - public bool UseOnlySupportedCountries - { - get => (bool)GetValue(UseOnlySupportedCountriesProperty); - set => SetValue(UseOnlySupportedCountriesProperty, value); - } + [DependencyProperty(DefaultValue = RenderFlagIndicatorType.Flat16)] + private RenderFlagIndicatorType renderFlagIndicatorType; - public static readonly DependencyProperty DefaultCultureIdentifierProperty = DependencyProperty.Register( - nameof(DefaultCultureIdentifier), - typeof(string), - typeof(CountrySelector), - new PropertyMetadata(default)); + [DependencyProperty(DefaultValue = true)] + private bool useOnlySupportedCountries; - public string? DefaultCultureIdentifier - { - get => (string?)GetValue(DefaultCultureIdentifierProperty); - set => SetValue(DefaultCultureIdentifierProperty, value); - } + [DependencyProperty] + private string defaultCultureIdentifier; - public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( - nameof(SelectedKey), - typeof(string), - typeof(CountrySelector), - new PropertyMetadata( - string.Empty, - OnSelectedKeyChanged)); + [DependencyProperty(DefaultValue = "", PropertyChangedCallback = nameof(OnSelectedKeyChanged))] + private string selectedKey; - public string SelectedKey - { - get => (string)GetValue(SelectedKeyProperty); - set => SetValue(SelectedKeyProperty, value); - } - - public static readonly DependencyProperty UpdateUiCultureOnChangeEventProperty = DependencyProperty.Register( - nameof(UpdateUiCultureOnChangeEvent), - typeof(bool), - typeof(CountrySelector), - new PropertyMetadata(defaultValue: true)); - - public bool UpdateUiCultureOnChangeEvent - { - get => (bool)GetValue(UpdateUiCultureOnChangeEventProperty); - set => SetValue(UpdateUiCultureOnChangeEventProperty, value); - } + [DependencyProperty(DefaultValue = true)] + private bool updateUiCultureOnChangeEvent; public event EventHandler>? SelectorChanged; @@ -180,19 +124,19 @@ private void UpdateDataOnUiCultureChanged() } else { - var dropDownFirstItemType = (DropDownFirstItemType)item.Culture.Lcid; - switch (dropDownFirstItemType) + var ddfItemType = (DropDownFirstItemType)item.Culture.Lcid; + switch (ddfItemType) { case DropDownFirstItemType.None: case DropDownFirstItemType.Blank: break; case DropDownFirstItemType.PleaseSelect: case DropDownFirstItemType.IncludeAll: - item.Culture.CountryEnglishName = dropDownFirstItemType.GetDescription(useLocalizedIfPossible: false); - item.Culture.CountryDisplayName = dropDownFirstItemType.GetDescription(); + item.Culture.CountryEnglishName = ddfItemType.GetDescription(useLocalizedIfPossible: false); + item.Culture.CountryDisplayName = ddfItemType.GetDescription(); break; default: - throw new SwitchCaseDefaultException(dropDownFirstItemType); + throw new SwitchCaseDefaultException(ddfItemType); } } } diff --git a/src/Atc.Wpf/Controls/Selectors/FontFamilySelector.xaml.cs b/src/Atc.Wpf/Controls/Selectors/FontFamilySelector.xaml.cs index 1edb34d4..0fd59339 100644 --- a/src/Atc.Wpf/Controls/Selectors/FontFamilySelector.xaml.cs +++ b/src/Atc.Wpf/Controls/Selectors/FontFamilySelector.xaml.cs @@ -5,31 +5,11 @@ public partial class FontFamilySelector private readonly ObservableCollectionEx items = new(); private string? lastKey; - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(FontFamilySelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } - - public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( - nameof(SelectedKey), - typeof(string), - typeof(FontFamilySelector), - new PropertyMetadata( - string.Empty, - OnSelectedKeyChanged)); - - public string SelectedKey - { - get => (string)GetValue(SelectedKeyProperty); - set => SetValue(SelectedKeyProperty, value); - } + [DependencyProperty(DefaultValue = "", PropertyChangedCallback = nameof(OnSelectedKeyChanged))] + private string selectedKey; public event EventHandler>? SelectorChanged; diff --git a/src/Atc.Wpf/Controls/Selectors/LanguageSelector.xaml.cs b/src/Atc.Wpf/Controls/Selectors/LanguageSelector.xaml.cs index 116f0bbd..0c1111ad 100644 --- a/src/Atc.Wpf/Controls/Selectors/LanguageSelector.xaml.cs +++ b/src/Atc.Wpf/Controls/Selectors/LanguageSelector.xaml.cs @@ -13,79 +13,23 @@ public partial class LanguageSelector private int? lastLcid; private bool processingUiCultureChanged; - public static readonly DependencyProperty DropDownFirstItemTypeProperty = DependencyProperty.Register( - nameof(DropDownFirstItemType), - typeof(DropDownFirstItemType), - typeof(LanguageSelector), - new PropertyMetadata(DropDownFirstItemType.None)); + [DependencyProperty(DefaultValue = DropDownFirstItemType.None)] + private DropDownFirstItemType dropDownFirstItemType; - public DropDownFirstItemType DropDownFirstItemType - { - get => (DropDownFirstItemType)GetValue(DropDownFirstItemTypeProperty); - set => SetValue(DropDownFirstItemTypeProperty, value); - } - - public static readonly DependencyProperty RenderFlagIndicatorTypeTypeProperty = DependencyProperty.Register( - nameof(RenderFlagIndicatorType), - typeof(RenderFlagIndicatorType), - typeof(LanguageSelector), - new PropertyMetadata(RenderFlagIndicatorType.Flat16)); - - public RenderFlagIndicatorType RenderFlagIndicatorType - { - get => (RenderFlagIndicatorType)GetValue(RenderFlagIndicatorTypeTypeProperty); - set => SetValue(RenderFlagIndicatorTypeTypeProperty, value); - } - - public static readonly DependencyProperty UseOnlySupportedLanguagesProperty = DependencyProperty.Register( - nameof(UseOnlySupportedLanguages), - typeof(bool), - typeof(LanguageSelector), - new PropertyMetadata(defaultValue: true)); - - public bool UseOnlySupportedLanguages - { - get => (bool)GetValue(UseOnlySupportedLanguagesProperty); - set => SetValue(UseOnlySupportedLanguagesProperty, value); - } + [DependencyProperty(DefaultValue = RenderFlagIndicatorType.Flat16)] + private RenderFlagIndicatorType renderFlagIndicatorType; - public static readonly DependencyProperty DefaultCultureIdentifierProperty = DependencyProperty.Register( - nameof(DefaultCultureIdentifier), - typeof(string), - typeof(LanguageSelector), - new PropertyMetadata(default)); + [DependencyProperty(DefaultValue = true)] + private bool useOnlySupportedLanguages; - public string? DefaultCultureIdentifier - { - get => (string?)GetValue(DefaultCultureIdentifierProperty); - set => SetValue(DefaultCultureIdentifierProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string defaultCultureIdentifier; - public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register( - nameof(SelectedKey), - typeof(string), - typeof(LanguageSelector), - new PropertyMetadata( - string.Empty, - OnSelectedKeyChanged)); + [DependencyProperty(DefaultValue = "", PropertyChangedCallback = nameof(OnSelectedKeyChanged))] + private string selectedKey; - public string SelectedKey - { - get => (string)GetValue(SelectedKeyProperty); - set => SetValue(SelectedKeyProperty, value); - } - - public static readonly DependencyProperty UpdateUiCultureOnChangeEventProperty = DependencyProperty.Register( - nameof(UpdateUiCultureOnChangeEvent), - typeof(bool), - typeof(LanguageSelector), - new PropertyMetadata(defaultValue: true)); - - public bool UpdateUiCultureOnChangeEvent - { - get => (bool)GetValue(UpdateUiCultureOnChangeEventProperty); - set => SetValue(UpdateUiCultureOnChangeEventProperty, value); - } + [DependencyProperty(DefaultValue = true)] + private bool updateUiCultureOnChangeEvent; public event EventHandler>? SelectorChanged; @@ -180,19 +124,19 @@ private void UpdateDataOnUiCultureChanged() } else { - var dropDownFirstItemType = (DropDownFirstItemType)item.Culture.Lcid; - switch (dropDownFirstItemType) + var ddfItemType = (DropDownFirstItemType)item.Culture.Lcid; + switch (ddfItemType) { case DropDownFirstItemType.None: case DropDownFirstItemType.Blank: break; case DropDownFirstItemType.PleaseSelect: case DropDownFirstItemType.IncludeAll: - item.Culture.LanguageEnglishName = dropDownFirstItemType.GetDescription(useLocalizedIfPossible: false); - item.Culture.LanguageDisplayName = dropDownFirstItemType.GetDescription(); + item.Culture.LanguageEnglishName = ddfItemType.GetDescription(useLocalizedIfPossible: false); + item.Culture.LanguageDisplayName = ddfItemType.GetDescription(); break; default: - throw new SwitchCaseDefaultException(dropDownFirstItemType); + throw new SwitchCaseDefaultException(ddfItemType); } } } diff --git a/src/Atc.Wpf/Helpers/CheckBoxHelper.cs b/src/Atc.Wpf/Helpers/CheckBoxHelper.cs index 67f6fc45..8e1f19e3 100644 --- a/src/Atc.Wpf/Helpers/CheckBoxHelper.cs +++ b/src/Atc.Wpf/Helpers/CheckBoxHelper.cs @@ -64,12 +64,11 @@ public static void SetCheckGlyphUnchecked( object? value) => d.SetValue(CheckGlyphUncheckedProperty, value); - public static readonly DependencyProperty CheckGlyphUncheckedTemplateProperty - = DependencyProperty.RegisterAttached( - "CheckGlyphUncheckedTemplate", - typeof(DataTemplate), - typeof(CheckBoxHelper), - new FrameworkPropertyMetadata(default(DataTemplate))); + public static readonly DependencyProperty CheckGlyphUncheckedTemplateProperty = DependencyProperty.RegisterAttached( + "CheckGlyphUncheckedTemplate", + typeof(DataTemplate), + typeof(CheckBoxHelper), + new FrameworkPropertyMetadata(default(DataTemplate))); public static DataTemplate? GetCheckGlyphUncheckedTemplate( DependencyObject d) @@ -125,12 +124,11 @@ public static void SetBorderBrushUnchecked( Brush? value) => d.SetValue(BorderBrushUncheckedProperty, value); - public static readonly DependencyProperty CheckBackgroundFillUncheckedProperty - = DependencyProperty.RegisterAttached( - "CheckBackgroundFillUnchecked", - typeof(Brush), - typeof(CheckBoxHelper), - new FrameworkPropertyMetadata(default(Brush))); + public static readonly DependencyProperty CheckBackgroundFillUncheckedProperty = DependencyProperty.RegisterAttached( + "CheckBackgroundFillUnchecked", + typeof(Brush), + typeof(CheckBoxHelper), + new FrameworkPropertyMetadata(default(Brush))); public static Brush? GetCheckBackgroundFillUnchecked( DependencyObject d) @@ -171,12 +169,11 @@ public static void SetCheckGlyphForegroundUnchecked( Brush? value) => d.SetValue(CheckGlyphForegroundUncheckedProperty, value); - public static readonly DependencyProperty ForegroundUncheckedMouseOverProperty - = DependencyProperty.RegisterAttached( - "ForegroundUncheckedMouseOver", - typeof(Brush), - typeof(CheckBoxHelper), - new FrameworkPropertyMetadata(default(Brush))); + public static readonly DependencyProperty ForegroundUncheckedMouseOverProperty = DependencyProperty.RegisterAttached( + "ForegroundUncheckedMouseOver", + typeof(Brush), + typeof(CheckBoxHelper), + new FrameworkPropertyMetadata(default(Brush))); public static Brush? GetForegroundUncheckedMouseOver( DependencyObject d) diff --git a/src/Atc.Wpf/Helpers/ScrollViewerHelper.cs b/src/Atc.Wpf/Helpers/ScrollViewerHelper.cs index 076ae817..db74f76e 100644 --- a/src/Atc.Wpf/Helpers/ScrollViewerHelper.cs +++ b/src/Atc.Wpf/Helpers/ScrollViewerHelper.cs @@ -3,11 +3,10 @@ namespace Atc.Wpf.Helpers; [SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "OK.")] public static class ScrollViewerHelper { - public static readonly DependencyProperty ScrollContentPresenterMarginProperty - = DependencyProperty.RegisterAttached( - "ScrollContentPresenterMargin", - typeof(Thickness), - typeof(ScrollViewerHelper)); + public static readonly DependencyProperty ScrollContentPresenterMarginProperty = DependencyProperty.RegisterAttached( + "ScrollContentPresenterMargin", + typeof(Thickness), + typeof(ScrollViewerHelper)); public static Thickness GetScrollContentPresenterMargin( ScrollViewer scrollViewer) @@ -18,14 +17,13 @@ public static void SetScrollContentPresenterMargin( Thickness value) => scrollViewer.SetValue(ScrollContentPresenterMarginProperty, value); - public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty - = DependencyProperty.RegisterAttached( - "VerticalScrollBarOnLeftSide", - typeof(bool), - typeof(ScrollViewerHelper), - new FrameworkPropertyMetadata( - BooleanBoxes.FalseBox, - FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits)); + public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty = DependencyProperty.RegisterAttached( + "VerticalScrollBarOnLeftSide", + typeof(bool), + typeof(ScrollViewerHelper), + new FrameworkPropertyMetadata( + BooleanBoxes.FalseBox, + FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits)); public static bool GetVerticalScrollBarOnLeftSide( UIElement element) diff --git a/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToBoolValueConverter.cs b/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToBoolValueConverter.cs index 374b98b1..358a8b55 100644 --- a/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToBoolValueConverter.cs +++ b/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToBoolValueConverter.cs @@ -1,5 +1,5 @@ // ReSharper disable SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault -// // ReSharper disable CheckNamespace +// ReSharper disable CheckNamespace namespace Atc.Wpf.ValueConverters; /// diff --git a/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverter.cs b/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverter.cs index 16a87f1c..68b9141c 100644 --- a/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverter.cs +++ b/src/Atc.Wpf/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverter.cs @@ -30,8 +30,12 @@ public object Convert( return operatorType switch { - BooleanOperatorType.AND => boolValues.All(b => b), - BooleanOperatorType.OR => boolValues.Any(b => b), + BooleanOperatorType.AND => boolValues.All(b => b) + ? Visibility.Visible + : Visibility.Collapsed, + BooleanOperatorType.OR => boolValues.Any(b => b) + ? Visibility.Visible + : Visibility.Collapsed, _ => throw new SwitchCaseDefaultException(nameof(operatorType)), }; } diff --git a/test/Atc.Wpf.Tests/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverterTests.cs b/test/Atc.Wpf.Tests/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverterTests.cs index 6a140f54..0e8df3e2 100644 --- a/test/Atc.Wpf.Tests/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverterTests.cs +++ b/test/Atc.Wpf.Tests/ValueConverters/BoolTo/MultiBoolToVisibilityVisibleValueConverterTests.cs @@ -11,10 +11,10 @@ public sealed class MultiBoolToVisibilityVisibleValueConverterTests private static readonly object[] Empty = []; [Theory] - [InlineData(true, nameof(AllTrue))] - [InlineData(false, nameof(OneFalse))] - [InlineData(true, nameof(Empty))] - public void Convert_AND_DefaultOperator(bool expected, string inputSetName) + [InlineData(Visibility.Visible, nameof(AllTrue))] + [InlineData(Visibility.Collapsed, nameof(OneFalse))] + [InlineData(Visibility.Visible, nameof(Empty))] + public void Convert_AND_DefaultOperator(Visibility expected, string inputSetName) { // Arrange var input = GetInput(inputSetName); @@ -27,11 +27,11 @@ public void Convert_AND_DefaultOperator(bool expected, string inputSetName) } [Theory] - [InlineData(true, nameof(AllTrue))] - [InlineData(true, nameof(OneFalse))] - [InlineData(false, nameof(AllFalse))] - [InlineData(false, nameof(Empty))] - public void Convert_OR_WithEnumParameter(bool expected, string inputSetName) + [InlineData(Visibility.Visible, nameof(AllTrue))] + [InlineData(Visibility.Visible, nameof(OneFalse))] + [InlineData(Visibility.Collapsed, nameof(AllFalse))] + [InlineData(Visibility.Collapsed, nameof(Empty))] + public void Convert_OR_WithEnumParameter(Visibility expected, string inputSetName) { // Arrange var input = GetInput(inputSetName); @@ -58,7 +58,7 @@ public void Convert_OR_WithStringParameter() culture: CultureInfo.InvariantCulture); // Assert - Assert.True((bool)actual!); + Assert.Equal(Visibility.Visible, actual!); } private static object[] GetInput(string name) => name switch diff --git a/tool/Atc.Wpf.Generator.FontIconResources/Atc.Wpf.Generator.FontIconResources.csproj b/tool/Atc.Wpf.Generator.FontIconResources/Atc.Wpf.Generator.FontIconResources.csproj index b73a08b3..866e2549 100644 --- a/tool/Atc.Wpf.Generator.FontIconResources/Atc.Wpf.Generator.FontIconResources.csproj +++ b/tool/Atc.Wpf.Generator.FontIconResources/Atc.Wpf.Generator.FontIconResources.csproj @@ -9,8 +9,8 @@ - - + + NU1701