From b99e1b6b2c0c410b9b093bc26fe382d88f9c84b3 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Tue, 29 Mar 2022 11:48:00 +0200 Subject: [PATCH] Cleanup attached properties --- .../DataGridTextColumn.cs | 23 ++++- src/Avalonia.Controls/Control.cs | 90 ------------------ .../Presenters/TextPresenter.cs | 55 +++++++++++ .../Primitives/TemplatedControl.cs | 91 +++++++++++++++++++ src/Avalonia.Controls/TextBlock.cs | 90 ++++++++++++++++++ .../Controls/Button.xaml | 2 +- .../Controls/CaptionButtons.xaml | 2 +- .../Controls/CheckBox.xaml | 2 +- .../Controls/DatePicker.xaml | 4 +- .../Controls/RepeatButton.xaml | 2 +- .../Controls/CaptionButtons.xaml | 2 +- .../Controls/ComboBox.xaml | 2 +- .../Controls/ComboBoxItem.xaml | 2 +- .../Controls/DatePicker.xaml | 4 +- .../Controls/RadioButton.xaml | 2 +- .../Controls/Slider.xaml | 4 +- .../Controls/TimePicker.xaml | 6 +- 17 files changed, 272 insertions(+), 111 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs index e7c8e67ff0..863910c226 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs @@ -33,7 +33,7 @@ namespace Avalonia.Controls /// Identifies the FontFamily dependency property. /// public static readonly AttachedProperty FontFamilyProperty = - TextBlock.FontFamilyProperty.AddOwner(); + TextElement.FontFamilyProperty.AddOwner(); /// /// Gets or sets the font name. @@ -48,7 +48,7 @@ namespace Avalonia.Controls /// Identifies the FontSize dependency property. /// public static readonly AttachedProperty FontSizeProperty = - TextBlock.FontSizeProperty.AddOwner(); + TextElement.FontSizeProperty.AddOwner(); /// /// Gets or sets the font size. @@ -65,7 +65,7 @@ namespace Avalonia.Controls /// Identifies the FontStyle dependency property. /// public static readonly AttachedProperty FontStyleProperty = - TextBlock.FontStyleProperty.AddOwner(); + TextElement.FontStyleProperty.AddOwner(); /// /// Gets or sets the font style. @@ -80,7 +80,7 @@ namespace Avalonia.Controls /// Identifies the FontWeight dependency property. /// public static readonly AttachedProperty FontWeightProperty = - TextBlock.FontWeightProperty.AddOwner(); + TextElement.FontWeightProperty.AddOwner(); /// /// Gets or sets the font weight or thickness. @@ -91,6 +91,21 @@ namespace Avalonia.Controls set => SetValue(FontWeightProperty, value); } + /// + /// Identifies the FontStretch dependency property. + /// + public static readonly AttachedProperty FontStretchProperty = + TextElement.FontStretchProperty.AddOwner(); + + /// + /// Gets or sets the font weight or thickness. + /// + public FontStretch FontStretch + { + get => GetValue(FontStretchProperty); + set => SetValue(FontStretchProperty, value); + } + /// /// Identifies the Foreground dependency property. /// diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index 3eb1f1c472..45c0d2948d 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -68,42 +68,6 @@ namespace Avalonia.Controls public static readonly AttachedProperty FlowDirectionProperty = AvaloniaProperty.RegisterAttached(nameof(FlowDirection), inherits: true); - /// - /// Defines the property. - /// - public static readonly AttachedProperty FontFamilyProperty = - TextElement.FontFamilyProperty.AddOwner(); - - /// - /// Defines the property. - /// - public static readonly AttachedProperty FontSizeProperty = - TextElement.FontSizeProperty.AddOwner(); - - /// - /// Defines the property. - /// - public static readonly AttachedProperty FontStyleProperty = - TextElement.FontStyleProperty.AddOwner(); - - /// - /// Defines the property. - /// - public static readonly AttachedProperty FontWeightProperty = - TextElement.FontWeightProperty.AddOwner(); - - /// - /// Defines the property. - /// - public static readonly AttachedProperty FontStretchProperty = - TextElement.FontStretchProperty.AddOwner(); - - /// - /// Defines the property. - /// - public static readonly AttachedProperty ForegroundProperty = - TextElement.ForegroundProperty.AddOwner(); - private DataTemplates? _dataTemplates; private IControl? _focusAdorner; private AutomationPeer? _automationPeer; @@ -162,60 +126,6 @@ namespace Avalonia.Controls set => SetValue(FlowDirectionProperty, value); } - /// - /// Gets or sets the font family. - /// - public FontFamily FontFamily - { - get { return GetValue(FontFamilyProperty); } - set { SetValue(FontFamilyProperty, value); } - } - - /// - /// Gets or sets the font size. - /// - public double FontSize - { - get { return GetValue(FontSizeProperty); } - set { SetValue(FontSizeProperty, value); } - } - - /// - /// Gets or sets the font style. - /// - public FontStyle FontStyle - { - get { return GetValue(FontStyleProperty); } - set { SetValue(FontStyleProperty, value); } - } - - /// - /// Gets or sets the font weight. - /// - public FontWeight FontWeight - { - get { return GetValue(FontWeightProperty); } - set { SetValue(FontWeightProperty, value); } - } - - /// - /// Gets or sets the font stretch. - /// - public FontStretch FontStretch - { - get { return GetValue(FontStretchProperty); } - set { SetValue(FontStretchProperty, value); } - } - - /// - /// Gets or sets a brush used to paint the text. - /// - public IBrush? Foreground - { - get { return GetValue(ForegroundProperty); } - set { SetValue(ForegroundProperty, value); } - } - /// /// Occurs when the user has completed a context input gesture, such as a right-click. /// diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 5267cc1d6e..ebd0196b80 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -8,6 +8,7 @@ using Avalonia.Utilities; using Avalonia.VisualTree; using Avalonia.Layout; using Avalonia.Media.Immutable; +using Avalonia.Controls.Documents; namespace Avalonia.Controls.Presenters { @@ -116,6 +117,60 @@ namespace Avalonia.Controls.Presenters set => SetAndRaise(TextProperty, ref _text, value); } + /// + /// Gets or sets the font family. + /// + public FontFamily FontFamily + { + get => TextElement.GetFontFamily(this); + set => TextElement.SetFontFamily(this, value); + } + + /// + /// Gets or sets the font size. + /// + public double FontSize + { + get => TextElement.GetFontSize(this); + set => TextElement.SetFontSize(this, value); + } + + /// + /// Gets or sets the font style. + /// + public FontStyle FontStyle + { + get => TextElement.GetFontStyle(this); + set => TextElement.SetFontStyle(this, value); + } + + /// + /// Gets or sets the font weight. + /// + public FontWeight FontWeight + { + get => TextElement.GetFontWeight(this); + set => TextElement.SetFontWeight(this, value); + } + + /// + /// Gets or sets the font stretch. + /// + public FontStretch FontStretch + { + get => TextElement.GetFontStretch(this); + set => TextElement.SetFontStretch(this, value); + } + + /// + /// Gets or sets a brush used to paint the text. + /// + public IBrush? Foreground + { + get => TextElement.GetForeground(this); + set => TextElement.SetForeground(this, value); + } + /// /// Gets or sets the control's text wrapping mode. /// diff --git a/src/Avalonia.Controls/Primitives/TemplatedControl.cs b/src/Avalonia.Controls/Primitives/TemplatedControl.cs index 212aaa27d6..795c307c54 100644 --- a/src/Avalonia.Controls/Primitives/TemplatedControl.cs +++ b/src/Avalonia.Controls/Primitives/TemplatedControl.cs @@ -1,4 +1,5 @@ using System; +using Avalonia.Controls.Documents; using Avalonia.Controls.Templates; using Avalonia.Interactivity; using Avalonia.Logging; @@ -37,6 +38,42 @@ namespace Avalonia.Controls.Primitives public static readonly StyledProperty CornerRadiusProperty = Border.CornerRadiusProperty.AddOwner(); + /// + /// Defines the property. + /// + public static readonly StyledProperty FontFamilyProperty = + TextElement.FontFamilyProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontSizeProperty = + TextElement.FontSizeProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontStyleProperty = + TextElement.FontStyleProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontWeightProperty = + TextElement.FontWeightProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontStretchProperty = + TextElement.FontStretchProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty ForegroundProperty = + TextElement.ForegroundProperty.AddOwner(); + /// /// Defines the property. /// @@ -119,6 +156,60 @@ namespace Avalonia.Controls.Primitives set { SetValue(CornerRadiusProperty, value); } } + /// + /// Gets or sets the font family used to draw the control's text. + /// + public FontFamily FontFamily + { + get { return GetValue(FontFamilyProperty); } + set { SetValue(FontFamilyProperty, value); } + } + + /// + /// Gets or sets the size of the control's text in points. + /// + public double FontSize + { + get { return GetValue(FontSizeProperty); } + set { SetValue(FontSizeProperty, value); } + } + + /// + /// Gets or sets the font style used to draw the control's text. + /// + public FontStyle FontStyle + { + get { return GetValue(FontStyleProperty); } + set { SetValue(FontStyleProperty, value); } + } + + /// + /// Gets or sets the font weight used to draw the control's text. + /// + public FontWeight FontWeight + { + get { return GetValue(FontWeightProperty); } + set { SetValue(FontWeightProperty, value); } + } + + /// + /// Gets or sets the font stretch used to draw the control's text. + /// + public FontStretch FontStretch + { + get { return GetValue(FontStretchProperty); } + set { SetValue(FontStretchProperty, value); } + } + + /// + /// Gets or sets the brush used to draw the control's text and other foreground elements. + /// + public IBrush? Foreground + { + get { return GetValue(ForegroundProperty); } + set { SetValue(ForegroundProperty, value); } + } + /// /// Gets or sets the padding placed between the border of the control and its content. /// diff --git a/src/Avalonia.Controls/TextBlock.cs b/src/Avalonia.Controls/TextBlock.cs index 8b8f8bac37..2abaf14419 100644 --- a/src/Avalonia.Controls/TextBlock.cs +++ b/src/Avalonia.Controls/TextBlock.cs @@ -28,6 +28,42 @@ namespace Avalonia.Controls public static readonly StyledProperty PaddingProperty = Decorator.PaddingProperty.AddOwner(); + /// + /// Defines the property. + /// + public static readonly StyledProperty FontFamilyProperty = + TextElement.FontFamilyProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontSizeProperty = + TextElement.FontSizeProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontStyleProperty = + TextElement.FontStyleProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontWeightProperty = + TextElement.FontWeightProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty FontStretchProperty = + TextElement.FontStretchProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty ForegroundProperty = + TextElement.ForegroundProperty.AddOwner(); + /// /// DependencyProperty for property. /// @@ -174,6 +210,60 @@ namespace Avalonia.Controls [Content] public InlineCollection Inlines { get; } + /// + /// Gets or sets the font family used to draw the control's text. + /// + public FontFamily FontFamily + { + get { return GetValue(FontFamilyProperty); } + set { SetValue(FontFamilyProperty, value); } + } + + /// + /// Gets or sets the size of the control's text in points. + /// + public double FontSize + { + get { return GetValue(FontSizeProperty); } + set { SetValue(FontSizeProperty, value); } + } + + /// + /// Gets or sets the font style used to draw the control's text. + /// + public FontStyle FontStyle + { + get { return GetValue(FontStyleProperty); } + set { SetValue(FontStyleProperty, value); } + } + + /// + /// Gets or sets the font weight used to draw the control's text. + /// + public FontWeight FontWeight + { + get { return GetValue(FontWeightProperty); } + set { SetValue(FontWeightProperty, value); } + } + + /// + /// Gets or sets the font stretch used to draw the control's text. + /// + public FontStretch FontStretch + { + get { return GetValue(FontStretchProperty); } + set { SetValue(FontStretchProperty, value); } + } + + /// + /// Gets or sets the brush used to draw the control's text and other foreground elements. + /// + public IBrush? Foreground + { + get { return GetValue(ForegroundProperty); } + set { SetValue(ForegroundProperty, value); } + } + /// /// Gets or sets the height of each line of content. /// diff --git a/src/Avalonia.Themes.Default/Controls/Button.xaml b/src/Avalonia.Themes.Default/Controls/Button.xaml index a8509f2976..3f8a94b005 100644 --- a/src/Avalonia.Themes.Default/Controls/Button.xaml +++ b/src/Avalonia.Themes.Default/Controls/Button.xaml @@ -18,7 +18,7 @@ Content="{TemplateBinding Content}" Padding="{TemplateBinding Padding}" RecognizesAccessKey="True" - Foreground="{TemplateBinding Foreground}" + TextElement.Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> diff --git a/src/Avalonia.Themes.Default/Controls/CaptionButtons.xaml b/src/Avalonia.Themes.Default/Controls/CaptionButtons.xaml index af56698ad5..9c1d4d0b1d 100644 --- a/src/Avalonia.Themes.Default/Controls/CaptionButtons.xaml +++ b/src/Avalonia.Themes.Default/Controls/CaptionButtons.xaml @@ -4,7 +4,7 @@ - +