diff --git a/.editorconfig b/.editorconfig index f0cb93b7..a040e8f1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -591,6 +591,8 @@ dotnet_diagnostic.MA0091.severity = none # Sender should be 'this' for dotnet_diagnostic.MA0131.severity = none # ArgumentNullException.ThrowIfNull should not be used with non-nullable types dotnet_diagnostic.SA1010.severity = none # Opening square brackets must be spaced correctly +dotnet_diagnostic.SA1311.severity = none # Static readonly fields must begin with upper case letter +dotnet_diagnostic.IDE1006.severity = none # Static readonly fields must begin with upper case letter dotnet_diagnostic.S107.severity = none # Methods should not have too many parameters dotnet_diagnostic.S1144.severity = none # Remove the unused internal class diff --git a/README.md b/README.md index ce97abaa..0df37bee 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This is a base libraries for building WPF application with the MVVM design patte | Nuget package | Description | Dependencies | |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|----------------------------------------------| | [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.svg?label=Atc.Wpf&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf) | Base Controls, ValueConverters, Extensions etc. | | -| [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.Controls.svg?label=Atc.Wpf.Controls&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf.Controls) | Miscellaneous UI Controls | | +| [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.Controls.svg?label=Atc.Wpf.Controls&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf.Controls) | Miscellaneous UI Controls | | | [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.Controls.Sample.svg?label=Atc.Wpf.Controls.Sample&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf.Controls.Sample) | Controls for creating WPF sample apps | | | [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.FontIcons.svg?label=Atc.Wpf.FontIcons&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf.FontIcons) | Render Svg and Img resources based on fonts | | | [![NuGet Version](https://img.shields.io/nuget/v/Atc.Wpf.Theming.svg?label=Atc.Wpf.Theming&logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Wpf.Theming) | Theming for Light & Dark mode for WPF base controls | | diff --git a/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj b/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj index 534ab2d4..a2af611e 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/SamplesWpfTheming/InputButton/ImageButtonView.xaml b/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageButtonView.xaml index 1a26fdb3..594bbef5 100644 --- a/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageButtonView.xaml +++ b/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageButtonView.xaml @@ -39,7 +39,10 @@ Orientation="Horizontal" Spacing="10"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageToggledButton.xaml.cs b/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageToggledButton.xaml.cs new file mode 100644 index 00000000..3274ca13 --- /dev/null +++ b/sample/Atc.Wpf.Sample/SamplesWpfTheming/InputButton/ImageToggledButton.xaml.cs @@ -0,0 +1,53 @@ +namespace Atc.Wpf.Sample.SamplesWpfTheming.InputButton; + +public partial class ImageToggledButton +{ + public ImageToggledButton() + { + InitializeComponent(); + + DataContext = this; + } + + [DependencyProperty] + private bool isBusy; + + [DependencyProperty] + private bool isConnected; + + [RelayCommand] + private async Task Connect() + { + IsBusy = true; + + await Task + .Delay(2_000) + .ConfigureAwait(false); + + await Application.Current.Dispatcher + .InvokeAsyncIfRequired(() => + { + IsConnected = true; + IsBusy = false; + }) + .ConfigureAwait(false); + } + + [RelayCommand] + private async Task Disconnect() + { + IsBusy = true; + + await Task + .Delay(500) + .ConfigureAwait(false); + + await Application.Current.Dispatcher + .InvokeAsyncIfRequired(() => + { + IsConnected = false; + IsBusy = false; + }) + .ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/sample/Atc.Wpf.Sample/SamplesWpfThemingTreeView.xaml b/sample/Atc.Wpf.Sample/SamplesWpfThemingTreeView.xaml index afc9ecdd..37c2e03a 100644 --- a/sample/Atc.Wpf.Sample/SamplesWpfThemingTreeView.xaml +++ b/sample/Atc.Wpf.Sample/SamplesWpfThemingTreeView.xaml @@ -29,6 +29,10 @@ Header="ImageButton" IsExpanded="True" SamplePath="InputButton.ImageButtonView" /> + - - + + diff --git a/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs index 9140bb85..7a24f52d 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/ClockPanelPicker.xaml.cs @@ -1,3 +1,4 @@ +// ReSharper disable InconsistentNaming namespace Atc.Wpf.Controls.BaseControls; public partial class ClockPanelPicker : INotifyPropertyChanged @@ -9,19 +10,12 @@ public partial class ClockPanelPicker : INotifyPropertyChanged public event PropertyChangedEventHandler? PropertyChanged; - public static readonly RoutedEvent SelectedClockChangedEvent = EventManager.RegisterRoutedEvent( - nameof(SelectedClockChanged), + [RoutedEvent( RoutingStrategy.Direct, - typeof(EventHandler), - typeof(ClockPanelPicker)); + HandlerType = typeof(EventHandler))] + private static readonly RoutedEvent selectedClockChanged; - public event EventHandler SelectedClockChanged - { - add => AddHandler(SelectedClockChangedEvent, value); - remove => RemoveHandler(SelectedClockChangedEvent, value); - } - - [DependencyProperty(DefaultValue = "default(DateTime?)")] + [DependencyProperty] private DateTime? selectedDateTime; public ClockPanelPicker() @@ -43,7 +37,8 @@ public ClockPanelPicker() SelectedKeyMinute = "0"; } - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) + protected virtual void OnPropertyChanged( + [CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } diff --git a/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs index 2f278abe..f9d964bc 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/ColorPicker.xaml.cs @@ -6,12 +6,12 @@ public partial class ColorPicker private RenderColorIndicatorType renderColorIndicatorType; [DependencyProperty( - DefaultValue = "Black", + DefaultValue = nameof(Brushes.Black), PropertyChangedCallback = nameof(OnColorValueChanged))] private Color? colorValue; [DependencyProperty( - DefaultValue = "Black", + DefaultValue = nameof(Brushes.Black), PropertyChangedCallback = nameof(OnBrushValueChanged))] private SolidColorBrush? brushValue; diff --git a/src/Atc.Wpf.Controls/BaseControls/DecimalXyBox.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/DecimalXyBox.xaml.cs index dce09ccb..d327ad24 100644 --- a/src/Atc.Wpf.Controls/BaseControls/DecimalXyBox.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/DecimalXyBox.xaml.cs @@ -26,123 +26,49 @@ public event RoutedPropertyChangedEventHandler ValueYChanged remove => RemoveHandler(ValueYChangedEvent, value); } - public static readonly DependencyProperty HideUpDownButtonsProperty = DependencyProperty.Register( - nameof(HideUpDownButtons), - typeof(bool), - typeof(DecimalXyBox), - new PropertyMetadata(BooleanBoxes.FalseBox)); - - public bool HideUpDownButtons - { - get => (bool)GetValue(HideUpDownButtonsProperty); - set => SetValue(HideUpDownButtonsProperty, value); - } - - public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register( - nameof(Maximum), - typeof(decimal), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - decimal.MaxValue, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - public decimal Maximum - { - get => (decimal)GetValue(MaximumProperty); - set => SetValue(MaximumProperty, value); - } - - public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register( - nameof(Minimum), - typeof(decimal), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - decimal.MinValue, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - public decimal Minimum - { - get => (decimal)GetValue(MinimumProperty); - set => SetValue(MinimumProperty, value); - } - - public static readonly DependencyProperty PrefixTextXProperty = DependencyProperty.Register( - nameof(PrefixTextX), - typeof(string), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - string.Empty, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - public string PrefixTextX - { - get => (string)GetValue(PrefixTextXProperty); - set => SetValue(PrefixTextXProperty, value); - } - - public static readonly DependencyProperty PrefixTextYProperty = DependencyProperty.Register( - nameof(PrefixTextY), - typeof(string), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - string.Empty, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - public string PrefixTextY - { - get => (string)GetValue(PrefixTextYProperty); - set => SetValue(PrefixTextYProperty, value); - } - - public static readonly DependencyProperty SuffixTextProperty = DependencyProperty.Register( - nameof(SuffixText), - typeof(string), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - string.Empty, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - public string SuffixText - { - get => (string)GetValue(SuffixTextProperty); - set => SetValue(SuffixTextProperty, value); - } - - public static readonly DependencyProperty ValueXProperty = DependencyProperty.Register( - nameof(ValueX), - typeof(decimal), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - defaultValue: 0m, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, - OnValueXLostFocus, - coerceValueCallback: null, - isAnimationProhibited: true, - UpdateSourceTrigger.LostFocus)); - - public decimal ValueX - { - get => (decimal)GetValue(ValueXProperty); - set => SetValue(ValueXProperty, value); - } - - public static readonly DependencyProperty ValueYProperty = DependencyProperty.Register( - nameof(ValueY), - typeof(decimal), - typeof(DecimalXyBox), - new FrameworkPropertyMetadata( - defaultValue: 0m, - FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, - OnValueYLostFocus, - coerceValueCallback: null, - isAnimationProhibited: true, - UpdateSourceTrigger.LostFocus)); - - public decimal ValueY - { - get => (decimal)GetValue(ValueYProperty); - set => SetValue(ValueYProperty, value); - } + [DependencyProperty(DefaultValue = false)] + private bool hideUpDownButtons; + + [DependencyProperty( + DefaultValue = PropertyDefaultValueConstants.MinValue, + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)] + private decimal minimum; + + [DependencyProperty( + DefaultValue = PropertyDefaultValueConstants.MaxValue, + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)] + private decimal maximum; + + [DependencyProperty( + DefaultValue = "", + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)] + private string prefixTextX; + + [DependencyProperty( + DefaultValue = "", + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)] + private string prefixTextY; + + [DependencyProperty( + DefaultValue = "", + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)] + private string suffixText; + + [DependencyProperty( + DefaultValue = 0, + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, + PropertyChangedCallback = nameof(OnValueXLostFocus), + IsAnimationProhibited = true, + DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus)] + private decimal valueX; + + [DependencyProperty( + DefaultValue = 0, + Flags = FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, + PropertyChangedCallback = nameof(OnValueYLostFocus), + IsAnimationProhibited = true, + DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus)] + private decimal valueY; public event EventHandler>? ValueXLostFocus; @@ -162,7 +88,11 @@ private void OnValueXChanged( return; } - RaiseEvent(new RoutedPropertyChangedEventArgs((decimal)e.OldValue, (decimal)e.NewValue, ValueXChangedEvent)); + RaiseEvent( + new RoutedPropertyChangedEventArgs( + (decimal)e.OldValue, + (decimal)e.NewValue, + ValueXChangedEvent)); } private void OnValueYChanged( @@ -174,7 +104,11 @@ private void OnValueYChanged( return; } - RaiseEvent(new RoutedPropertyChangedEventArgs((decimal)e.OldValue, (decimal)e.NewValue, ValueYChangedEvent)); + RaiseEvent( + new RoutedPropertyChangedEventArgs( + (decimal)e.OldValue, + (decimal)e.NewValue, + ValueYChangedEvent)); } private static void OnValueXLostFocus( diff --git a/src/Atc.Wpf.Controls/BaseControls/DirectoryPicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/DirectoryPicker.xaml.cs index 7d1336f0..fa5e5f6d 100644 --- a/src/Atc.Wpf.Controls/BaseControls/DirectoryPicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/DirectoryPicker.xaml.cs @@ -1,4 +1,5 @@ // ReSharper disable UnusedParameter.Local +// ReSharper disable InconsistentNaming namespace Atc.Wpf.Controls.BaseControls; [SuppressMessage("Naming", "CA1721:Property names should not match get methods", Justification = "OK.")] @@ -22,7 +23,7 @@ public event RoutedPropertyChangedEventHandler ValueChanged typeof(DirectoryInfo), typeof(DirectoryPicker), new FrameworkPropertyMetadata( - default(DirectoryInfo?), + defaultValue: null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValuePropertyChanged, (o, value) => CoerceValue(o, value).Item1)); @@ -38,7 +39,7 @@ public DirectoryInfo? Value typeof(string), typeof(DirectoryPicker), new FrameworkPropertyMetadata( - default(string?), + defaultValue: null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDisplayValuePropertyChanged, (o, value) => CoerceDisplayValue(o, value).Item1)); @@ -49,101 +50,29 @@ public string? DisplayValue set => SetValue(FullNameProperty, value); } - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - nameof(Title), - typeof(string), - typeof(DirectoryPicker), - new PropertyMetadata(default(string))); + [DependencyProperty] + private string title; - public string Title - { - get => (string)GetValue(TitleProperty); - set => SetValue(TitleProperty, value); - } + [DependencyProperty] + private bool showClearTextButton; - public static readonly DependencyProperty ShowClearTextButtonProperty = DependencyProperty.Register( - nameof(ShowClearTextButton), - typeof(bool), - typeof(DirectoryPicker), - new PropertyMetadata(default(bool))); + [DependencyProperty(DefaultValue = "")] + private string watermarkText; - public bool ShowClearTextButton - { - get => (bool)GetValue(ShowClearTextButtonProperty); - set => SetValue(ShowClearTextButtonProperty, value); - } + [DependencyProperty(DefaultValue = TextAlignment.Left)] + private TextAlignment watermarkAlignment; - public static readonly DependencyProperty WatermarkTextProperty = DependencyProperty.Register( - nameof(WatermarkText), - typeof(string), - typeof(DirectoryPicker), - new PropertyMetadata(defaultValue: string.Empty)); + [DependencyProperty(DefaultValue = TextTrimming.None)] + private TextTrimming watermarkTrimming; - public string WatermarkText - { - get => (string)GetValue(WatermarkTextProperty); - set => SetValue(WatermarkTextProperty, value); - } - - public static readonly DependencyProperty WatermarkAlignmentProperty = DependencyProperty.Register( - nameof(WatermarkAlignment), - typeof(TextAlignment), - typeof(DirectoryPicker), - new PropertyMetadata(default(TextAlignment))); + [DependencyProperty(DefaultValue = "")] + private string defaultDirectory; - public TextAlignment WatermarkAlignment - { - get => (TextAlignment)GetValue(WatermarkAlignmentProperty); - set => SetValue(WatermarkAlignmentProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string initialDirectory; - public static readonly DependencyProperty WatermarkTrimmingProperty = DependencyProperty.Register( - nameof(WatermarkTrimming), - typeof(TextTrimming), - typeof(DirectoryPicker), - new PropertyMetadata(default(TextTrimming))); - - public TextTrimming WatermarkTrimming - { - get => (TextTrimming)GetValue(WatermarkTrimmingProperty); - set => SetValue(WatermarkTrimmingProperty, value); - } - - public static readonly DependencyProperty DefaultDirectoryProperty = DependencyProperty.Register( - nameof(DefaultDirectory), - typeof(string), - typeof(DirectoryPicker), - new PropertyMetadata(string.Empty)); - - public string DefaultDirectory - { - get => (string)GetValue(DefaultDirectoryProperty); - set => SetValue(DefaultDirectoryProperty, value); - } - - public static readonly DependencyProperty InitialDirectoryProperty = DependencyProperty.Register( - nameof(InitialDirectory), - typeof(string), - typeof(DirectoryPicker), - new PropertyMetadata(string.Empty)); - - public string InitialDirectory - { - get => (string)GetValue(InitialDirectoryProperty); - set => SetValue(InitialDirectoryProperty, value); - } - - public static readonly DependencyProperty RootDirectoryProperty = DependencyProperty.Register( - nameof(RootDirectory), - typeof(string), - typeof(DirectoryPicker), - new PropertyMetadata(string.Empty)); - - public string RootDirectory - { - get => (string)GetValue(RootDirectoryProperty); - set => SetValue(RootDirectoryProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string rootDirectory; public DirectoryPicker() { diff --git a/src/Atc.Wpf.Controls/BaseControls/FilePicker.xaml.cs b/src/Atc.Wpf.Controls/BaseControls/FilePicker.xaml.cs index e4a6eb74..720c52bf 100644 --- a/src/Atc.Wpf.Controls/BaseControls/FilePicker.xaml.cs +++ b/src/Atc.Wpf.Controls/BaseControls/FilePicker.xaml.cs @@ -22,7 +22,7 @@ public event RoutedPropertyChangedEventHandler ValueChanged typeof(FileInfo), typeof(FilePicker), new FrameworkPropertyMetadata( - default(FileInfo?), + defaultValue: null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValuePropertyChanged, (o, value) => CoerceValue(o, value).Item1)); @@ -38,7 +38,7 @@ public FileInfo? Value typeof(string), typeof(FilePicker), new FrameworkPropertyMetadata( - default(string?), + defaultValue: null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDisplayValuePropertyChanged, (o, value) => CoerceDisplayValue(o, value).Item1)); @@ -49,138 +49,38 @@ public string? DisplayValue set => SetValue(FullNameProperty, value); } - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - nameof(Title), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(default(string))); - - public string Title - { - get => (string)GetValue(TitleProperty); - set => SetValue(TitleProperty, value); - } - - public static readonly DependencyProperty ShowClearTextButtonProperty = DependencyProperty.Register( - nameof(ShowClearTextButton), - typeof(bool), - typeof(FilePicker), - new PropertyMetadata(BooleanBoxes.FalseBox)); - - public bool ShowClearTextButton - { - get => (bool)GetValue(ShowClearTextButtonProperty); - set => SetValue(ShowClearTextButtonProperty, value); - } - - public static readonly DependencyProperty WatermarkTextProperty = DependencyProperty.Register( - nameof(WatermarkText), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(defaultValue: string.Empty)); + [DependencyProperty] + private string title; - public string WatermarkText - { - get => (string)GetValue(WatermarkTextProperty); - set => SetValue(WatermarkTextProperty, value); - } + [DependencyProperty] + private bool showClearTextButton; - public static readonly DependencyProperty WatermarkAlignmentProperty = DependencyProperty.Register( - nameof(WatermarkAlignment), - typeof(TextAlignment), - typeof(FilePicker), - new PropertyMetadata(default(TextAlignment))); + [DependencyProperty(DefaultValue = "")] + private string watermarkText; - public TextAlignment WatermarkAlignment - { - get => (TextAlignment)GetValue(WatermarkAlignmentProperty); - set => SetValue(WatermarkAlignmentProperty, value); - } + [DependencyProperty(DefaultValue = TextAlignment.Left)] + private TextAlignment watermarkAlignment; - public static readonly DependencyProperty WatermarkTrimmingProperty = DependencyProperty.Register( - nameof(WatermarkTrimming), - typeof(TextTrimming), - typeof(FilePicker), - new PropertyMetadata(default(TextTrimming))); + [DependencyProperty(DefaultValue = TextTrimming.None)] + private TextTrimming watermarkTrimming; - public TextTrimming WatermarkTrimming - { - get => (TextTrimming)GetValue(WatermarkTrimmingProperty); - set => SetValue(WatermarkTrimmingProperty, value); - } + [DependencyProperty] + private bool allowOnlyExisting; - public static readonly DependencyProperty AllowOnlyExistingProperty = DependencyProperty.Register( - nameof(AllowOnlyExisting), - typeof(bool), - typeof(FilePicker), - new PropertyMetadata(BooleanBoxes.FalseBox)); + [DependencyProperty] + private bool usePreviewPane; - public bool AllowOnlyExisting - { - get => (bool)GetValue(AllowOnlyExistingProperty); - set => SetValue(AllowOnlyExistingProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string filter; - public static readonly DependencyProperty UsePreviewPaneProperty = DependencyProperty.Register( - nameof(UsePreviewPane), - typeof(bool), - typeof(FilePicker), - new PropertyMetadata(BooleanBoxes.FalseBox)); + [DependencyProperty(DefaultValue = "")] + private string defaultDirectory; - public bool UsePreviewPane - { - get => (bool)GetValue(UsePreviewPaneProperty); - set => SetValue(UsePreviewPaneProperty, value); - } - - public static readonly DependencyProperty FilterProperty = DependencyProperty.Register( - nameof(Filter), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(string.Empty)); - - public string Filter - { - get => (string)GetValue(FilterProperty); - set => SetValue(FilterProperty, value); - } - - public static readonly DependencyProperty DefaultDirectoryProperty = DependencyProperty.Register( - nameof(DefaultDirectory), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(string.Empty)); - - public string DefaultDirectory - { - get => (string)GetValue(DefaultDirectoryProperty); - set => SetValue(DefaultDirectoryProperty, value); - } - - public static readonly DependencyProperty InitialDirectoryProperty = DependencyProperty.Register( - nameof(InitialDirectory), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(string.Empty)); - - public string InitialDirectory - { - get => (string)GetValue(InitialDirectoryProperty); - set => SetValue(InitialDirectoryProperty, value); - } - - public static readonly DependencyProperty RootDirectoryProperty = DependencyProperty.Register( - nameof(RootDirectory), - typeof(string), - typeof(FilePicker), - new PropertyMetadata(string.Empty)); - - public string RootDirectory - { - get => (string)GetValue(RootDirectoryProperty); - set => SetValue(RootDirectoryProperty, value); - } + [DependencyProperty(DefaultValue = "")] + private string initialDirectory; + [DependencyProperty(DefaultValue = "")] + private string rootDirectory; public FilePicker() { InitializeComponent(); diff --git a/src/Atc.Wpf.Controls/BaseControls/ImageButton.cs b/src/Atc.Wpf.Controls/BaseControls/ImageButton.cs index 7cb72ae4..e7244e9c 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ImageButton.cs +++ b/src/Atc.Wpf.Controls/BaseControls/ImageButton.cs @@ -1,130 +1,44 @@ -using Atc.Wpf.Controls.Progressing; - namespace Atc.Wpf.Controls.BaseControls; -public sealed class ImageButton : Button +public partial class ImageButton : Button { - public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register( - nameof(ImageWidth), - typeof(int), - typeof(ImageButton), - new PropertyMetadata(16)); + [DependencyProperty( + DefaultValue = null, + PropertyChangedCallback = nameof(OnImageLocationChanged))] + private ImageLocation? imageLocation; - public int ImageWidth - { - get => (int)GetValue(ImageWidthProperty); - set => SetValue(ImageWidthProperty, value); - } + [DependencyProperty(DefaultValue = 16)] + private int imageWidth; - public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register( - nameof(ImageHeight), - typeof(int), - typeof(ImageButton), - new PropertyMetadata(16)); + [DependencyProperty(DefaultValue = 16)] + private int imageHeight; - public int ImageHeight - { - get => (int)GetValue(ImageHeightProperty); - set => SetValue(ImageHeightProperty, value); - } + [DependencyProperty(DefaultValue = 5d)] + private double imageContentSpacing; - public static readonly DependencyProperty ImageLocationProperty = DependencyProperty.Register( - nameof(ImageLocation), - typeof(ImageLocation?), - typeof(ImageButton), - new PropertyMetadata( - defaultValue: null, - PropertyChangedCallback)); + [DependencyProperty(DefaultValue = 0d)] + private double imageBorderSpacing; - public ImageLocation? ImageLocation - { - get => (ImageLocation)GetValue(ImageLocationProperty); - set => SetValue(ImageLocationProperty, value); - } + [DependencyProperty] + private ImageSource? imageSource; - public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register( - nameof(ImageSource), - typeof(ImageSource), - typeof(ImageButton), - new PropertyMetadata(defaultValue: default)); + [DependencyProperty(DefaultValue = "")] + private string svgImageSource; - public ImageSource ImageSource - { - get => (ImageSource)GetValue(ImageSourceProperty); - set => SetValue(ImageSourceProperty, value); - } - - public static readonly DependencyProperty SvgImageSourceProperty = DependencyProperty.Register( - nameof(SvgImageSource), - typeof(string), - typeof(ImageButton), - new PropertyMetadata(defaultValue: string.Empty)); + [DependencyProperty] + private Color? svgImageOverrideColor; - public string SvgImageSource - { - get => (string)GetValue(ImageSourceProperty); - set => SetValue(ImageSourceProperty, value); - } + [DependencyProperty] + private int rowIndex; - public static readonly DependencyProperty SvgImageOverrideColorProperty = DependencyProperty.Register( - nameof(SvgImageOverrideColor), - typeof(Color?), - typeof(ImageButton), - new PropertyMetadata(default(Color?))); - - public Color? SvgImageOverrideColor - { - get => (Color?)GetValue(SvgImageOverrideColorProperty); - set => SetValue(SvgImageOverrideColorProperty, value); - } + [DependencyProperty] + private int columnIndex; - public static readonly DependencyProperty RowIndexProperty = DependencyProperty.Register( - nameof(RowIndex), - typeof(int), - typeof(ImageButton), - new PropertyMetadata(0)); + [DependencyProperty(DefaultValue = LoadingIndicatorType.ArcsRing)] + private LoadingIndicatorType loadingIndicatorMode; - public int RowIndex - { - get => (int)GetValue(RowIndexProperty); - set => SetValue(RowIndexProperty, value); - } - - public static readonly DependencyProperty ColumnIndexProperty = DependencyProperty.Register( - nameof(ColumnIndex), - typeof(int), - typeof(ImageButton), - new PropertyMetadata(0)); - - public int ColumnIndex - { - get => (int)GetValue(ColumnIndexProperty); - set => SetValue(ColumnIndexProperty, value); - } - - public static readonly DependencyProperty LoadingIndicatorModeProperty = DependencyProperty.Register( - nameof(LoadingIndicatorMode), - typeof(LoadingIndicatorType), - typeof(ImageButton), - new PropertyMetadata(LoadingIndicatorType.ArcsRing)); - - public LoadingIndicatorType LoadingIndicatorMode - { - get => (LoadingIndicatorType)GetValue(LoadingIndicatorModeProperty); - set => SetValue(LoadingIndicatorModeProperty, value); - } - - public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register( - nameof(IsBusy), - typeof(bool), - typeof(ImageButton), - new PropertyMetadata(BooleanBoxes.FalseBox)); - - public bool IsBusy - { - get => (bool)GetValue(IsBusyProperty); - set => SetValue(IsBusyProperty, value); - } + [DependencyProperty] + private bool isBusy; static ImageButton() { @@ -135,10 +49,10 @@ static ImageButton() public ImageButton() { - this.SetCurrentValue(ImageLocationProperty, Controls.ImageLocation.Left); + SetCurrentValue(ImageLocationProperty, Controls.ImageLocation.Left); } - private static void PropertyChangedCallback( + private static void OnImageLocationChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { diff --git a/src/Atc.Wpf.Controls/BaseControls/ImageButton.xaml b/src/Atc.Wpf.Controls/BaseControls/ImageButton.xaml index 9a7fa299..7d3bd52c 100644 --- a/src/Atc.Wpf.Controls/BaseControls/ImageButton.xaml +++ b/src/Atc.Wpf.Controls/BaseControls/ImageButton.xaml @@ -9,6 +9,9 @@ + + + @@ -35,34 +38,56 @@ x:Name="PART_LoadingIndicator" Width="{Binding Path=ImageWidth, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}" Height="{Binding Path=ImageHeight, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}" - Margin="{Binding Path=ImageLocation, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}, Converter={x:Static valueConverters:ImageLocationToMarginValueConverter.Instance}}" Padding="2" IsActive="False" Mode="{Binding Path=LoadingIndicatorMode, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}" - Visibility="Collapsed" /> + Visibility="Collapsed"> + + + + + + + + + Visibility="Collapsed"> + + + + + + + + + Visibility="Collapsed"> + + + + + + + + + @@ -89,6 +115,7 @@ + @@ -99,11 +126,17 @@ + + + + + +