diff --git a/Directory.Build.props b/Directory.Build.props index d431ad27..7b983407 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -45,7 +45,7 @@ - + diff --git a/README.md b/README.md index a23510ec..ce97abaa 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ 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. | Atc | -| [![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 | Atc.Wpf & Atc.Wpf.Theming | -| [![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 | Atc.Wpf & Atc.Wpf.Theming & Atc.Wpf.Controls | -| [![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 | Atc.Wpf | -| [![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 | Atc.Wpf | +| [![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. |
  • Atc
  • Atc.XamlToolkit
  • Atc.XamlToolkit.Wpf
| +| [![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 |
  • Atc.Wpf
  • Atc.Wpf.Theming
  • Atc.XamlToolkit
  • Atc.XamlToolkit.Wpf
| +| [![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 |
  • Atc.Wpf
  • Atc.Wpf.Theming
  • Atc.Wpf.Controls
| +| [![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 |
  • Atc.Wpf
| +| [![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 |
  • Atc.Wpf
  • Atc.XamlToolkit
  • Atc.XamlToolkit.Wpf
| ## 🔎 Demonstration Application diff --git a/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj b/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj index 3c760d08..5ac68aae 100644 --- a/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj +++ b/sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj @@ -8,7 +8,7 @@ - $(NoWarn);WPF0001;CS0169;CS8618 + $(NoWarn);WPF0001;CS0169;CS8618;CA1823 @@ -51,8 +51,8 @@ - - + + diff --git a/sample/Atc.Wpf.Sample/SamplesWpfControls/Monitoring/ApplicationMonitorView.xaml.cs b/sample/Atc.Wpf.Sample/SamplesWpfControls/Monitoring/ApplicationMonitorView.xaml.cs index aa7f1128..b25b45a0 100644 --- a/sample/Atc.Wpf.Sample/SamplesWpfControls/Monitoring/ApplicationMonitorView.xaml.cs +++ b/sample/Atc.Wpf.Sample/SamplesWpfControls/Monitoring/ApplicationMonitorView.xaml.cs @@ -24,19 +24,8 @@ public ApplicationMonitorView() } } - public static readonly DependencyProperty EnableTimerProperty = DependencyProperty.Register( - nameof(EnableTimer), - typeof(bool), - typeof(ApplicationMonitorView), - new PropertyMetadata( - defaultValue: false, - propertyChangedCallback: OnEnableTimerChanged)); - - public bool EnableTimer - { - get => (bool)GetValue(EnableTimerProperty); - set => SetValue(EnableTimerProperty, value); - } + [DependencyProperty(PropertyChangedCallback = nameof(OnEnableTimerChanged))] + private bool enableTimer; private static void OnEnableTimerChanged( DependencyObject d, diff --git a/src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj b/src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj index e60ad279..532cc872 100644 --- a/src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj +++ b/src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj @@ -7,6 +7,11 @@ Atc.Wpf.Controls.Sample wpf;controls;sample A base library for building Sample WPF application. + README.md + + + + $(NoWarn);CS0169;CS0649;CS8618;CA1823 diff --git a/src/Atc.Wpf.Controls.Sample/GlobalUsings.cs b/src/Atc.Wpf.Controls.Sample/GlobalUsings.cs index e1608955..2ade60b0 100644 --- a/src/Atc.Wpf.Controls.Sample/GlobalUsings.cs +++ b/src/Atc.Wpf.Controls.Sample/GlobalUsings.cs @@ -8,5 +8,6 @@ global using System.Windows.Media; global using Atc.Helpers; +global using Atc.XamlToolkit.Controls.Attributes; global using Atc.XamlToolkit.Messaging; global using Atc.XamlToolkit.Mvvm; \ No newline at end of file diff --git a/src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml.cs b/src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml.cs index 7818f883..44996889 100644 --- a/src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml.cs +++ b/src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml.cs @@ -2,17 +2,8 @@ namespace Atc.Wpf.Controls.Sample; public partial class SampleViewerView { - public static readonly DependencyProperty HeaderForegroundProperty = DependencyProperty.Register( - nameof(HeaderForeground), - typeof(SolidColorBrush), - typeof(SampleViewerView), - new PropertyMetadata(Brushes.Chocolate)); - - public SolidColorBrush HeaderForeground - { - get => (SolidColorBrush)GetValue(HeaderForegroundProperty); - set => SetValue(HeaderForegroundProperty, value); - } + [DependencyProperty(DefaultValue = "Brushes.Chocolate")] + private SolidColorBrush headerForeground; public SampleViewerView() { diff --git a/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj b/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj index 0c2b8db2..0207cb0c 100644 --- a/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj +++ b/src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj @@ -7,6 +7,7 @@ Atc.Wpf.Controls wpf;controls A base library for building WPF application. + README.md @@ -42,8 +43,8 @@ - - + + diff --git a/src/Atc.Wpf.FontIcons/Atc.Wpf.FontIcons.csproj b/src/Atc.Wpf.FontIcons/Atc.Wpf.FontIcons.csproj index f46b8bab..c3fed28b 100644 --- a/src/Atc.Wpf.FontIcons/Atc.Wpf.FontIcons.csproj +++ b/src/Atc.Wpf.FontIcons/Atc.Wpf.FontIcons.csproj @@ -7,6 +7,7 @@ Atc.Wpf.FontIcons wpf;controls.font,icons A base library for building WPF application. + README.md diff --git a/src/Atc.Wpf.Theming/Atc.Wpf.Theming.csproj b/src/Atc.Wpf.Theming/Atc.Wpf.Theming.csproj index 16e966d4..45c22b00 100644 --- a/src/Atc.Wpf.Theming/Atc.Wpf.Theming.csproj +++ b/src/Atc.Wpf.Theming/Atc.Wpf.Theming.csproj @@ -7,6 +7,7 @@ Atc.Wpf.Theming wpf;theming A base library for building WPF application with theming. + README.md $(NoWarn);SYSLIB0051 diff --git a/src/Atc.Wpf/Atc.Wpf.csproj b/src/Atc.Wpf/Atc.Wpf.csproj index fbd04a1c..b8c29080 100644 --- a/src/Atc.Wpf/Atc.Wpf.csproj +++ b/src/Atc.Wpf/Atc.Wpf.csproj @@ -7,6 +7,11 @@ Atc.Wpf wpf;mvvm,relaycommand A base library for building WPF application with the MVVM design pattern. + README.md + + + + $(NoWarn);CS0169;CS0649;CS8618;CA1823 @@ -1008,6 +1013,8 @@ + + diff --git a/src/Atc.Wpf/ControlAttach/RectangleAttach.cs b/src/Atc.Wpf/ControlAttach/RectangleAttach.cs index 26e6a0bf..2ddee775 100644 --- a/src/Atc.Wpf/ControlAttach/RectangleAttach.cs +++ b/src/Atc.Wpf/ControlAttach/RectangleAttach.cs @@ -1,24 +1,9 @@ namespace Atc.Wpf.ControlAttach; -[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "OK.")] -public static class RectangleAttach +public static partial class RectangleAttach { - public static readonly DependencyProperty CircularProperty = DependencyProperty.RegisterAttached( - "Circular", - typeof(bool), - typeof(RectangleAttach), - new PropertyMetadata( - defaultValue: BooleanBoxes.FalseBox, - propertyChangedCallback: OnCircularChanged)); - - public static void SetCircular( - DependencyObject element, - bool value) - => element.SetValue(CircularProperty, BooleanBoxes.Box(value)); - - public static bool GetCircular( - DependencyObject element) - => (bool)element.GetValue(CircularProperty); + [AttachedProperty(PropertyChangedCallback = nameof(OnCircularChanged))] + private static bool circular; private static void OnCircularChanged( DependencyObject d, diff --git a/src/Atc.Wpf/Controls/Layouts/AutoGrid.cs b/src/Atc.Wpf/Controls/Layouts/AutoGrid.cs index 96b66f9e..150b6142 100644 --- a/src/Atc.Wpf/Controls/Layouts/AutoGrid.cs +++ b/src/Atc.Wpf/Controls/Layouts/AutoGrid.cs @@ -7,264 +7,93 @@ namespace Atc.Wpf.Controls.Layouts; /// /// Partially based on work at http://rachel53461.wordpress.com/2011/09/17/wpf-grids-rowcolumn-count-properties. /// -public sealed class AutoGrid : Grid +public sealed partial class AutoGrid : Grid { - /// - /// The child horizontal alignment property - /// - public static readonly DependencyProperty ChildHorizontalAlignmentProperty = DependencyProperty.Register( - nameof(ChildHorizontalAlignment), - typeof(HorizontalAlignment?), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - defaultValue: null, - FrameworkPropertyMetadataOptions.AffectsMeasure, - OnChildHorizontalAlignmentChanged)); - - /// - /// The child margin property - /// - public static readonly DependencyProperty ChildMarginProperty = DependencyProperty.Register( - nameof(ChildMargin), - typeof(Thickness?), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - defaultValue: null, - FrameworkPropertyMetadataOptions.AffectsMeasure, - OnChildMarginChanged)); - - /// - /// The child vertical alignment property - /// - public static readonly DependencyProperty ChildVerticalAlignmentProperty = DependencyProperty.Register( - nameof(ChildVerticalAlignment), - typeof(VerticalAlignment?), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - defaultValue: null, - FrameworkPropertyMetadataOptions.AffectsMeasure, - OnChildVerticalAlignmentChanged)); - - /// - /// The column count property - /// - public static readonly DependencyProperty ColumnCountProperty = DependencyProperty.RegisterAttached( - nameof(ColumnCount), - typeof(int), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - 1, - FrameworkPropertyMetadataOptions.AffectsMeasure, - ColumnCountChanged)); - - /// - /// The columns property - /// - public static readonly DependencyProperty ColumnsProperty = DependencyProperty.RegisterAttached( - nameof(Columns), - typeof(string), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - string.Empty, - FrameworkPropertyMetadataOptions.AffectsMeasure, - ColumnsChanged)); - - /// - /// The column width property - /// - public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.RegisterAttached( - nameof(ColumnWidth), - typeof(GridLength), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - GridLength.Auto, - FrameworkPropertyMetadataOptions.AffectsMeasure, - FixedColumnWidthChanged)); - - /// - /// The is automatic indexing property - /// - public static readonly DependencyProperty IsAutoIndexingProperty = DependencyProperty.Register( - nameof(IsAutoIndexing), - typeof(bool), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - defaultValue: true, - FrameworkPropertyMetadataOptions.AffectsMeasure)); - - /// - /// The orientation property - /// - public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( - nameof(Orientation), - typeof(Orientation), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - Orientation.Horizontal, - FrameworkPropertyMetadataOptions.AffectsMeasure)); - - /// - /// The row count property - /// - public static readonly DependencyProperty RowCountProperty = DependencyProperty.RegisterAttached( - nameof(RowCount), - typeof(int), - typeof(AutoGrid), - new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.AffectsMeasure, RowCountChanged)); - - /// - /// The row height property - /// - public static readonly DependencyProperty RowHeightProperty = DependencyProperty.RegisterAttached( - nameof(RowHeight), - typeof(GridLength), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - GridLength.Auto, - FrameworkPropertyMetadataOptions.AffectsMeasure, - FixedRowHeightChanged)); - - /// - /// The rows property - /// - public static readonly DependencyProperty RowsProperty = DependencyProperty.RegisterAttached( - nameof(Rows), - typeof(string), - typeof(AutoGrid), - new FrameworkPropertyMetadata( - string.Empty, - FrameworkPropertyMetadataOptions.AffectsMeasure, - RowsChanged)); - - /// - /// Gets or sets the child horizontal alignment. - /// - /// The child horizontal alignment. - [Category("Layout")] - [Description("Presets the horizontal alignment of all child controls")] - public HorizontalAlignment? ChildHorizontalAlignment - { - get => (HorizontalAlignment?)GetValue(ChildHorizontalAlignmentProperty); - set => SetValue(ChildHorizontalAlignmentProperty, value); - } - - /// - /// Gets or sets the child margin. - /// - /// The child margin. - [Category("Layout")] - [Description("Presets the margin of all child controls")] - public Thickness? ChildMargin - { - get => (Thickness?)GetValue(ChildMarginProperty); - set => SetValue(ChildMarginProperty, value); - } - - /// - /// Gets or sets the child vertical alignment. - /// - /// The child vertical alignment. - [Category("Layout")] - [Description("Presets the vertical alignment of all child controls")] - public VerticalAlignment? ChildVerticalAlignment - { - get => (VerticalAlignment?)GetValue(ChildVerticalAlignmentProperty); - set => SetValue(ChildVerticalAlignmentProperty, value); - } - - /// - /// Gets or sets the column count. - /// - [Category("Layout")] - [Description("Defines a set number of columns")] - public int ColumnCount - { - get => (int)GetValue(ColumnCountProperty); - set => SetValue(ColumnCountProperty, value); - } - - /// - /// Gets or sets the columns. - /// - [Category("Layout")] - [Description("Defines all columns using comma separated grid length notation")] - public string Columns - { - get => (string)GetValue(ColumnsProperty); - set => SetValue(ColumnsProperty, value); - } - - /// - /// Gets or sets the fixed column width. - /// - [Category("Layout")] - [Description("Presets the width of all columns set using the ColumnCount property")] - public GridLength ColumnWidth - { - get => (GridLength)GetValue(ColumnWidthProperty); - set => SetValue(ColumnWidthProperty, value); - } - - /// - /// Gets or sets a value indicating whether the children are automatically indexed. - /// - /// The default is . - /// Note that if children are already indexed, setting this property to will not remove their indices. - /// - /// - [Category("Layout")] - [Description("Set to false to disable the auto layout functionality")] - public bool IsAutoIndexing - { - get => (bool)GetValue(IsAutoIndexingProperty); - set => SetValue(IsAutoIndexingProperty, value); - } - - /// - /// Gets or sets the orientation. - /// The default is Vertical. - /// - /// The orientation. - [Category("Layout")] - [Description("Defines the directionality of the autolayout. Use vertical for a column first layout, horizontal for a row first layout.")] - public Orientation Orientation - { - get => (Orientation)GetValue(OrientationProperty); - set => SetValue(OrientationProperty, value); - } - - /// - /// Gets or sets the number of rows. - /// - [Category("Layout")] - [Description("Defines a set number of rows")] - public int RowCount - { - get => (int)GetValue(RowCountProperty); - set => SetValue(RowCountProperty, value); - } - - /// - /// Gets or sets the fixed row height. - /// - [Category("Layout")] - [Description("Presets the height of all rows set using the RowCount property")] - public GridLength RowHeight - { - get => (GridLength)GetValue(RowHeightProperty); - set => SetValue(RowHeightProperty, value); - } - - /// - /// Gets or sets the rows. - /// - [Category("Layout")] - [Description("Defines all rows using comma separated grid length notation")] - public string Rows - { - get => (string)GetValue(RowsProperty); - set => SetValue(RowsProperty, value); - } + [DependencyProperty( + Category = "Layout", + Description = "Presets the horizontal alignment of all child controls", + DefaultValue = null, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(OnChildHorizontalAlignmentChanged))] + private HorizontalAlignment? childHorizontalAlignment; + + [DependencyProperty( + Category = "Layout", + Description = "Presets the margin of all child controls", + DefaultValue = null, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(OnChildMarginChanged))] + private Thickness? childMargin; + + [DependencyProperty( + Category = "Layout", + Description = "Presets the vertical alignment of all child controls", + DefaultValue = null, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(OnChildVerticalAlignmentChanged))] + private VerticalAlignment? childVerticalAlignment; + + [DependencyProperty( + Category = "Layout", + Description = "Defines a set number of columns", + DefaultValue = 1, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(ColumnCountChanged))] + private int columnCount; + + [DependencyProperty( + Category = "Layout", + Description = "Defines all columns using comma separated grid length notation", + DefaultValue = "", + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(ColumnsChanged))] + private string columns; + + [DependencyProperty( + Category = "Layout", + Description = "Presets the width of all columns set using the ColumnCount property", + DefaultValue = "GridLength.Auto", + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(FixedColumnWidthChanged))] + private GridLength columnWidth; + + [DependencyProperty( + Category = "Layout", + Description = "Set to false to disable the auto layout functionality", + DefaultValue = true, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure)] + private bool isAutoIndexing; + + [DependencyProperty( + Category = "Layout", + Description = "Defines the directionality of the auto-layout. Use vertical for a column first layout, horizontal for a row first layout.", + DefaultValue = "Orientation.Horizontal", + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure)] + private Orientation orientation; + + [DependencyProperty( + Category = "Layout", + Description = "Defines a set number of rows", + DefaultValue = 1, + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(RowCountChanged))] + private int rowCount; + + [DependencyProperty( + Category = "Layout", + Description = "Presets the height of all rows set using the RowCount property", + DefaultValue = "GridLength.Auto", + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(FixedRowHeightChanged))] + private GridLength rowHeight; + + [DependencyProperty( + Category = "Layout", + Description = "Defines all rows using comma separated grid length notation", + DefaultValue = "", + Flags = FrameworkPropertyMetadataOptions.AffectsMeasure, + PropertyChangedCallback = nameof(RowsChanged))] + private string rows; /// /// Handles the column count changed event. @@ -616,16 +445,16 @@ private void ApplyChildLayout( private void PerformLayout() { var fillRowFirst = Orientation == Orientation.Horizontal; - var rowCount = RowDefinitions.Count; - var colCount = ColumnDefinitions.Count; + var rowDefCount = RowDefinitions.Count; + var colDefCount = ColumnDefinitions.Count; - if (rowCount == 0 || colCount == 0) + if (rowDefCount == 0 || colDefCount == 0) { return; } var position = 0; - var skip = new bool[rowCount, colCount]; + var skip = new bool[rowDefCount, colDefCount]; foreach (UIElement child in Children) { var childIsCollapsed = child.Visibility == Visibility.Collapsed; @@ -633,13 +462,13 @@ private void PerformLayout() { if (fillRowFirst) { - var row = Clamp(position / colCount, rowCount - 1); - var col = Clamp(position % colCount, colCount - 1); + var row = Clamp(position / colDefCount, rowDefCount - 1); + var col = Clamp(position % colDefCount, colDefCount - 1); if (skip[row, col]) { position++; - row = position / colCount; - col = position % colCount; + row = position / colDefCount; + col = position % colDefCount; } SetRow(child, row); @@ -654,13 +483,13 @@ private void PerformLayout() } else { - var row = Clamp(position % rowCount, rowCount - 1); - var col = Clamp(position / rowCount, colCount - 1); + var row = Clamp(position % rowDefCount, rowDefCount - 1); + var col = Clamp(position / rowDefCount, colDefCount - 1); if (skip[row, col]) { position++; - row = position % rowCount; - col = position / rowCount; + row = position % rowDefCount; + col = position / rowDefCount; } SetRow(child, row); diff --git a/src/Atc.Wpf/Controls/Layouts/GridEx.cs b/src/Atc.Wpf/Controls/Layouts/GridEx.cs index ad8ff01e..f267172e 100644 --- a/src/Atc.Wpf/Controls/Layouts/GridEx.cs +++ b/src/Atc.Wpf/Controls/Layouts/GridEx.cs @@ -23,53 +23,21 @@ namespace Atc.Wpf.Controls.Layouts; /// ]]> /// [SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "OK.")] -public sealed class GridEx : Grid +public sealed partial class GridEx : Grid { - /// - /// The rows dependency property. - /// - private static readonly DependencyProperty RowsProperty = DependencyProperty.Register( - nameof(Rows), - typeof(string), - typeof(GridEx), - new PropertyMetadata( - defaultValue: null, - OnRowsChanged)); - - /// - /// The columns dependency property. - /// - private static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register( - nameof(Columns), - typeof(string), - typeof(GridEx), - new PropertyMetadata( - defaultValue: null, - OnColumnsChanged)); - - /// - /// Gets or sets the rows. - /// - /// The rows. - [Category("Layout")] - [Description("The rows property.")] - public string Rows - { - get => (string)GetValue(RowsProperty); - set => SetValue(RowsProperty, value); - } - - /// - /// Gets or sets the columns. - /// - /// The columns. - [Category("Layout")] - [Description("The columns property.")] - public string Columns - { - get => (string)GetValue(ColumnsProperty); - set => SetValue(ColumnsProperty, value); - } + [DependencyProperty( + Category = "Layout", + Description = "The rows property", + DefaultValue = null, + PropertyChangedCallback = nameof(OnRowsChanged))] + private string rows; + + [DependencyProperty( + Category = "Layout", + Description = "The columns property", + DefaultValue = null, + PropertyChangedCallback = nameof(OnColumnsChanged))] + private string columns; /// /// Called when the rows property is changed. diff --git a/src/Atc.Wpf/Controls/Layouts/GridLines.cs b/src/Atc.Wpf/Controls/Layouts/GridLines.cs index 326d72da..630db287 100644 --- a/src/Atc.Wpf/Controls/Layouts/GridLines.cs +++ b/src/Atc.Wpf/Controls/Layouts/GridLines.cs @@ -1,50 +1,29 @@ namespace Atc.Wpf.Controls.Layouts; -public sealed class GridLines : ContentControl +public sealed partial class GridLines : ContentControl { private readonly Canvas containerCanvas = new(); - public static readonly DependencyProperty HorizontalStepProperty = DependencyProperty.Register( - nameof(HorizontalStep), - typeof(double), - typeof(GridLines), - new PropertyMetadata( - 20d, - (sender, _) => ((GridLines)sender).ReDrawGridLines())); - - public double HorizontalStep - { - get => (double)GetValue(HorizontalStepProperty); - set => SetValue(HorizontalStepProperty, value); - } - - public static readonly DependencyProperty VerticalStepProperty = DependencyProperty.Register( - nameof(VerticalStep), - typeof(double), - typeof(GridLines), - new PropertyMetadata( - 20d, - (sender, _) => ((GridLines)sender).ReDrawGridLines())); - - public double VerticalStep - { - get => (double)GetValue(VerticalStepProperty); - set => SetValue(VerticalStepProperty, value); - } - - public static readonly DependencyProperty LineBrushProperty = DependencyProperty.Register( - nameof(LineBrush), - typeof(Brush), - typeof(GridLines), - new PropertyMetadata( - defaultValue: null, - (sender, _) => ((GridLines)sender).ReDrawGridLines())); - - public Brush LineBrush - { - get => (Brush)GetValue(LineBrushProperty); - set => SetValue(LineBrushProperty, value); - } + [DependencyProperty( + Category = "Layout", + Description = "The horizontal step property", + DefaultValue = 20d, + PropertyChangedCallback = nameof(OnReDrawGridLines))] + private double horizontalStep; + + [DependencyProperty( + Category = "Layout", + Description = "The vertical step property", + DefaultValue = 20d, + PropertyChangedCallback = nameof(OnReDrawGridLines))] + private double verticalStep; + + [DependencyProperty( + Category = "Layout", + Description = "The line brush property", + DefaultValue = "DeepPink", + PropertyChangedCallback = nameof(OnReDrawGridLines))] + private Brush lineBrush; public GridLines() { @@ -57,6 +36,18 @@ public GridLines() SizeChanged += OnGridLinesSizeChanged; } + private static void OnReDrawGridLines( + DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + if (d is not GridLines gridLines) + { + return; + } + + gridLines.ReDrawGridLines(); + } + private void OnLoaded( object sender, RoutedEventArgs e) @@ -76,7 +67,7 @@ private void ReDrawGridLines() var currentMainWindow = Application.Current.MainWindow; if (currentMainWindow is not null) { - var matrix = PresentationSource.FromVisual(currentMainWindow)!.CompositionTarget.TransformToDevice; + var matrix = PresentationSource.FromVisual(currentMainWindow)!.CompositionTarget!.TransformToDevice; var dpiFactor = 1 / matrix.M11; thickness = 1 * dpiFactor; } diff --git a/src/Atc.Wpf/Extensions/DispatcherExtensions.cs b/src/Atc.Wpf/Extensions/DispatcherExtensions.cs deleted file mode 100644 index 3a8e7c37..00000000 --- a/src/Atc.Wpf/Extensions/DispatcherExtensions.cs +++ /dev/null @@ -1,85 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace System.Windows.Threading; - -/// -/// Provides extension methods for the class to invoke actions based on thread access requirements. -/// -public static class DispatcherExtensions -{ - /// - /// Invokes the specified action on the dispatcher thread if required, otherwise executes it directly. - /// - /// The dispatcher to use for invoking the action. - /// The action to be executed. - /// The priority at which the action is invoked, if required. The default is . - /// Thrown if or is null. - public static void InvokeIfRequired( - this Dispatcher dispatcher, - Action action, - DispatcherPriority priority = DispatcherPriority.Normal) - { - ArgumentNullException.ThrowIfNull(dispatcher); - ArgumentNullException.ThrowIfNull(action); - - if (dispatcher.CheckAccess()) - { - action(); - } - else - { - dispatcher.Invoke(action, priority); - } - } - - /// - /// Asynchronously invokes the specified action on the dispatcher thread if required, otherwise executes it directly. - /// - /// The dispatcher to use for invoking the action. - /// The action to be executed. - /// The priority at which the action is invoked, if required. The default is . - /// A task representing the asynchronous operation. - /// Thrown if or is null. - public static async Task InvokeAsyncIfRequired( - this Dispatcher dispatcher, - Action action, - DispatcherPriority priority = DispatcherPriority.Normal) - { - ArgumentNullException.ThrowIfNull(dispatcher); - ArgumentNullException.ThrowIfNull(action); - - if (dispatcher.CheckAccess()) - { - action(); - } - else - { - await dispatcher.InvokeAsync(action, priority); - } - } - - /// - /// Asynchronously begins invoking the specified action on the dispatcher thread if required, otherwise executes it directly. - /// - /// The dispatcher to use for invoking the action. - /// The action to be executed. - /// The priority at which the action is invoked, if required. The default is . - /// A task representing the asynchronous operation. - /// Thrown if or is null. - public static async Task BeginInvokeIfRequired( - this Dispatcher dispatcher, - Action action, - DispatcherPriority priority = DispatcherPriority.Normal) - { - ArgumentNullException.ThrowIfNull(dispatcher); - ArgumentNullException.ThrowIfNull(action); - - if (dispatcher.CheckAccess()) - { - action(); - } - else - { - await dispatcher.BeginInvoke(action, priority); - } - } -} \ No newline at end of file diff --git a/src/Atc.Wpf/GlobalUsings.cs b/src/Atc.Wpf/GlobalUsings.cs index fedfb003..2028ca25 100644 --- a/src/Atc.Wpf/GlobalUsings.cs +++ b/src/Atc.Wpf/GlobalUsings.cs @@ -60,5 +60,6 @@ global using Atc.Wpf.ValueConverters; global using Atc.Wpf.WindowsNative.Structs; global using Atc.Wpf.WindowsNative.User32; +global using Atc.XamlToolkit.Controls.Attributes; global using Microsoft.Extensions.Logging; \ No newline at end of file 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 9006ccf0..70e056f6 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