Browse Source

Merge branch 'master' into feature/nested-styles

pull/8024/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
593be4503d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
  2. 3
      samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
  3. 20
      src/Avalonia.Base/Layout/Layoutable.cs
  4. 141
      src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
  5. 6
      src/Avalonia.Controls/Button.cs
  6. 303
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs
  7. 797
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs
  8. 87
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerDateValidationErrorEventArgs.cs
  9. 31
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerFormat.cs
  10. 4
      src/Avalonia.Controls/MenuBase.cs
  11. 4
      src/Avalonia.Controls/MenuItem.cs
  12. 4
      src/Avalonia.Controls/NativeMenuItemBase.cs
  13. 4
      src/Avalonia.Controls/RepeatButton.cs
  14. 110
      src/Avalonia.Controls/TextBox.cs
  15. 17
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
  16. 17
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
  17. 252
      src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml
  18. 97
      tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs

13
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -364,12 +364,17 @@ HRESULT WindowBaseImpl::GetPosition(AvnPoint *ret) {
return E_POINTER;
}
auto frame = [Window frame];
if(Window != nullptr) {
auto frame = [Window frame];
ret->X = frame.origin.x;
ret->Y = frame.origin.y + frame.size.height;
ret->X = frame.origin.x;
ret->Y = frame.origin.y + frame.size.height;
*ret = ConvertPointY(*ret);
*ret = ConvertPointY(*ret);
} else
{
*ret = lastPositionSet;
}
return S_OK;
}

3
samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml

@ -10,8 +10,7 @@
Margin="0,16,0,0"
HorizontalAlignment="Center"
Spacing="16">
<StackPanel Orientation="Vertical"
Width="200">
<StackPanel Orientation="Vertical">
<TextBlock Text="SelectedDateFormat: Short"/>
<CalendarDatePicker Name="DatePicker1"
SelectedDateFormat="Short"

20
src/Avalonia.Base/Layout/Layoutable.cs

@ -141,7 +141,6 @@ namespace Avalonia.Layout
static Layoutable()
{
AffectsMeasure<Layoutable>(
IsVisibleProperty,
WidthProperty,
HeightProperty,
MinWidthProperty,
@ -791,6 +790,25 @@ namespace Avalonia.Layout
{
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == IsVisibleProperty)
{
DesiredSize = default;
// All changes to visibility cause the parent element to be notified.
this.GetVisualParent<ILayoutable>()?.ChildDesiredSizeChanged(this);
// We only invalidate outselves when visibility is changed to true.
if (change.GetNewValue<bool>())
{
InvalidateMeasure();
}
}
}
/// <inheritdoc/>
protected sealed override void OnVisualParentChanged(IVisual? oldParent, IVisual? newParent)
{

141
src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml

@ -1,87 +1,51 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles.Resources>
<Thickness x:Key="DataGridTextColumnCellTextBlockMargin">12,0,12,0</Thickness>
<x:Double x:Key="ListAccentLowOpacity">0.6</x:Double>
<x:Double x:Key="ListAccentMediumOpacity">0.8</x:Double>
<Thickness x:Key="DataGridTextColumnCellTextBlockMargin">12,0,12,0</Thickness>
<StreamGeometry x:Key="DataGridSortIconDescendingPath">M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z</StreamGeometry>
<StreamGeometry x:Key="DataGridSortIconAscendingPath">M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z</StreamGeometry>
<StreamGeometry x:Key="DataGridRowGroupHeaderIconClosedPath">M515 93l930 931l-930 931l90 90l1022 -1021l-1022 -1021z</StreamGeometry>
<StreamGeometry x:Key="DataGridRowGroupHeaderIconOpenedPath">M1939 1581l90 -90l-1005 -1005l-1005 1005l90 90l915 -915z</StreamGeometry>
<SolidColorBrush x:Key="DataGridColumnHeaderForegroundBrush" Color="{DynamicResource SystemBaseMediumColor}" />
<SolidColorBrush x:Key="DataGridColumnHeaderBackgroundBrush" Color="{DynamicResource SystemAltHighColor}" />
<SolidColorBrush x:Key="DataGridColumnHeaderHoveredBackgroundBrush" Color="{DynamicResource SystemListLowColor}" />
<SolidColorBrush x:Key="DataGridColumnHeaderPressedBackgroundBrush" Color="{DynamicResource SystemListMediumColor}" />
<SolidColorBrush x:Key="DataGridColumnHeaderDraggedBackgroundBrush" Color="{DynamicResource SystemChromeMediumLowColor}" />
<SolidColorBrush x:Key="DataGridRowGroupHeaderBackgroundBrush" Color="{DynamicResource SystemChromeMediumColor}" />
<SolidColorBrush x:Key="DataGridRowGroupHeaderPressedBackgroundBrush" Color="{DynamicResource SystemListMediumColor}" />
<SolidColorBrush x:Key="DataGridRowGroupHeaderForegroundBrush" Color="{DynamicResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="DataGridRowGroupHeaderHoveredBackgroundBrush" Color="{DynamicResource SystemListLowColor}" />
<StaticResource x:Key="DataGridRowBackgroundBrush" ResourceKey="SystemControlTransparentBrush" />
<SolidColorBrush x:Key="DataGridRowSelectedBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
<StaticResource x:Key="DataGridRowSelectedBackgroundOpacity" ResourceKey="ListAccentLowOpacity" />
<SolidColorBrush x:Key="DataGridRowSelectedHoveredBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
<StaticResource x:Key="DataGridRowSelectedHoveredBackgroundOpacity" ResourceKey="ListAccentMediumOpacity" />
<SolidColorBrush x:Key="DataGridRowSelectedUnfocusedBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
<StaticResource x:Key="DataGridRowSelectedUnfocusedBackgroundOpacity" ResourceKey="ListAccentLowOpacity" />
<SolidColorBrush x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
<StaticResource x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundOpacity" ResourceKey="ListAccentMediumOpacity" />
<SolidColorBrush x:Key="DataGridRowHoveredBackgroundColor" Color="{DynamicResource SystemListLowColor}" />
<SolidColorBrush x:Key="DataGridRowInvalidBrush" Color="{DynamicResource SystemErrorTextColor}" />
<SolidColorBrush x:Key="DataGridRowHeaderForegroundBrush" Color="{DynamicResource SystemBaseMediumColor}" />
<SolidColorBrush x:Key="DataGridRowHeaderBackgroundBrush" Color="{DynamicResource SystemAltHighColor}" />
<StaticResource x:Key="DataGridCellBackgroundBrush" ResourceKey="SystemControlTransparentBrush" />
<SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="{DynamicResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="{DynamicResource SystemAltMediumColor}" />
<SolidColorBrush x:Key="DataGridCellInvalidBrush" Color="{DynamicResource SystemErrorTextColor}" />
<SolidColorBrush x:Key="DataGridGridLinesBrush"
Color="{StaticResource SystemBaseMediumLowColor}"
Opacity="0.4" />
<SolidColorBrush x:Key="DataGridDropLocationIndicatorBackground"
Color="#3F4346" />
<SolidColorBrush x:Key="DataGridDisabledVisualElementBackground"
Color="#8CFFFFFF" />
<SolidColorBrush x:Key="DataGridFillerGridLinesBrush"
Color="Transparent" />
<SolidColorBrush x:Key="DataGridCurrencyVisualPrimaryBrush"
Color="Transparent" />
<StaticResource x:Key="DataGridColumnHeaderBackgroundColor"
ResourceKey="SystemAltHighColor" />
<SolidColorBrush x:Key="DataGridColumnHeaderBackgroundBrush"
Color="{StaticResource DataGridColumnHeaderBackgroundColor}" />
<StaticResource x:Key="DataGridScrollBarsSeparatorBackground"
ResourceKey="SystemChromeLowColor" />
<StaticResource x:Key="DataGridColumnHeaderForegroundBrush"
ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="DataGridColumnHeaderHoveredBackgroundColor"
ResourceKey="SystemListLowColor" />
<StaticResource x:Key="DataGridColumnHeaderPressedBackgroundColor"
ResourceKey="SystemListMediumColor" />
<StaticResource x:Key="DataGridColumnHeaderDraggedBackgroundBrush"
ResourceKey="SystemControlBackgroundChromeMediumLowBrush" />
<StaticResource x:Key="DataGridColumnHeaderPointerOverBrush"
ResourceKey="SystemControlHighlightListLowBrush" />
<StaticResource x:Key="DataGridColumnHeaderPressedBrush"
ResourceKey="SystemControlHighlightListMediumBrush" />
<StaticResource x:Key="DataGridDetailsPresenterBackgroundBrush"
ResourceKey="SystemControlBackgroundChromeMediumLowBrush" />
<StaticResource x:Key="DataGridFillerColumnGridLinesBrush"
ResourceKey="DataGridFillerGridLinesBrush" />
<StaticResource x:Key="DataGridRowSelectedBackgroundColor"
ResourceKey="SystemAccentColor" />
<StaticResource x:Key="DataGridRowSelectedBackgroundOpacity"
ResourceKey="ListAccentLowOpacity" />
<StaticResource x:Key="DataGridRowSelectedHoveredBackgroundColor"
ResourceKey="SystemAccentColor" />
<StaticResource x:Key="DataGridRowSelectedHoveredBackgroundOpacity"
ResourceKey="ListAccentMediumOpacity" />
<StaticResource x:Key="DataGridRowSelectedUnfocusedBackgroundColor"
ResourceKey="SystemAccentColor" />
<StaticResource x:Key="DataGridRowSelectedUnfocusedBackgroundOpacity"
ResourceKey="ListAccentLowOpacity" />
<StaticResource x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundColor"
ResourceKey="SystemAccentColor" />
<StaticResource x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundOpacity"
ResourceKey="ListAccentMediumOpacity" />
<StaticResource x:Key="DataGridRowHeaderForegroundBrush"
ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="DataGridRowHeaderBackgroundBrush"
ResourceKey="SystemControlBackgroundAltHighBrush" />
<StaticResource x:Key="DataGridRowGroupHeaderBackgroundBrush"
ResourceKey="SystemControlBackgroundChromeMediumBrush" />
<StaticResource x:Key="DataGridRowGroupHeaderHoveredBackgroundBrush"
ResourceKey="SystemControlBackgroundListLowBrush" />
<StaticResource x:Key="DataGridRowGroupHeaderPressedBackgroundBrush"
ResourceKey="SystemControlBackgroundListMediumBrush" />
<StaticResource x:Key="DataGridRowGroupHeaderForegroundBrush"
ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="DataGridRowInvalidBrush"
ResourceKey="SystemErrorTextColor" />
<StaticResource x:Key="DataGridCellBackgroundBrush"
ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="DataGridCellFocusVisualPrimaryBrush"
ResourceKey="SystemControlFocusVisualPrimaryBrush" />
<StaticResource x:Key="DataGridCellFocusVisualSecondaryBrush"
ResourceKey="SystemControlFocusVisualSecondaryBrush" />
<StaticResource x:Key="DataGridCellInvalidBrush"
ResourceKey="SystemErrorTextColor" />
Opacity="0.4"
Color="{DynamicResource SystemBaseMediumLowColor}" />
<StaticResource x:Key="DataGridCurrencyVisualPrimaryBrush" ResourceKey="SystemControlTransparentBrush" />
<SolidColorBrush x:Key="DataGridDetailsPresenterBackgroundBrush" Color="{DynamicResource SystemChromeMediumLowColor}" />
<StaticResource x:Key="DataGridFillerColumnGridLinesBrush" ResourceKey="SystemControlTransparentBrush" />
</Styles.Resources>
<Style Selector="DataGridCell">
@ -252,10 +216,10 @@
</Style>
<Style Selector="DataGridColumnHeader:pointerover /template/ Grid#PART_ColumnHeaderRoot">
<Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderHoveredBackgroundColor}" />
<Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderHoveredBackgroundBrush}" />
</Style>
<Style Selector="DataGridColumnHeader:pressed /template/ Grid#PART_ColumnHeaderRoot">
<Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderPressedBackgroundColor}" />
<Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderPressedBackgroundBrush}" />
</Style>
<Style Selector="DataGridColumnHeader:dragIndicator">
@ -336,29 +300,30 @@
</Style>
<Style Selector="DataGridRow /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource SystemControlTransparentBrush}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowBackgroundBrush}" />
</Style>
<Style Selector="DataGridRow:pointerover /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource SystemListLowColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowHoveredBackgroundColor}" />
</Style>
<Style Selector="DataGridRow:selected /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRow:selected:pointerover /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRow:selected:focus /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRow:selected:pointerover:focus /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRowHeader">
<Setter Property="Foreground" Value="{DynamicResource DataGridRowHeaderForegroundBrush}" />
<Setter Property="Background" Value="{DynamicResource DataGridRowHeaderBackgroundBrush}" />
<Setter Property="Focusable" Value="False" />
<Setter Property="SeparatorBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
@ -410,25 +375,25 @@
</Style>
<Style Selector="DataGridRowHeader /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource SystemControlTransparentBrush}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowBackgroundBrush}" />
</Style>
<Style Selector="DataGridRow:pointerover DataGridRowHeader /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource SystemListLowColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowHoveredBackgroundColor}" />
</Style>
<Style Selector="DataGridRowHeader:selected /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRow:pointerover DataGridRowHeader:selected /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRowHeader:selected:focus /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedBackgroundOpacity}" />
</Style>
<Style Selector="DataGridRow:pointerover DataGridRowHeader:selected:focus /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundColor}" />
<Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundBrush}" />
<Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundOpacity}" />
</Style>

6
src/Avalonia.Controls/Button.cs

@ -309,6 +309,8 @@ namespace Avalonia.Controls
IsPressed = false;
e.Handled = true;
}
base.OnKeyUp(e);
}
/// <summary>
@ -393,6 +395,8 @@ namespace Avalonia.Controls
/// <inheritdoc/>
protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
{
base.OnPointerCaptureLost(e);
IsPressed = false;
}
@ -407,6 +411,8 @@ namespace Avalonia.Controls
/// <inheritdoc/>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
UnregisterFlyoutEvents(Flyout);
RegisterFlyoutEvents(Flyout);
UpdatePseudoClasses();

303
src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs

@ -0,0 +1,303 @@
using System;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Layout;
namespace Avalonia.Controls
{
/// <inheritdoc/>
public partial class CalendarDatePicker
{
/// <summary>
/// Defines the <see cref="DisplayDate"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, DateTime> DisplayDateProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime>(
nameof(DisplayDate),
o => o.DisplayDate,
(o, v) => o.DisplayDate = v);
/// <summary>
/// Defines the <see cref="DisplayDateStart"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, DateTime?> DisplayDateStartProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(DisplayDateStart),
o => o.DisplayDateStart,
(o, v) => o.DisplayDateStart = v);
/// <summary>
/// Defines the <see cref="DisplayDateEnd"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, DateTime?> DisplayDateEndProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(DisplayDateEnd),
o => o.DisplayDateEnd,
(o, v) => o.DisplayDateEnd = v);
/// <summary>
/// Defines the <see cref="FirstDayOfWeek"/> property.
/// </summary>
public static readonly StyledProperty<DayOfWeek> FirstDayOfWeekProperty =
AvaloniaProperty.Register<CalendarDatePicker, DayOfWeek>(nameof(FirstDayOfWeek));
/// <summary>
/// Defines the <see cref="IsDropDownOpen"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, bool> IsDropDownOpenProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, bool>(
nameof(IsDropDownOpen),
o => o.IsDropDownOpen,
(o, v) => o.IsDropDownOpen = v);
/// <summary>
/// Defines the <see cref="IsTodayHighlighted"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsTodayHighlightedProperty =
AvaloniaProperty.Register<CalendarDatePicker, bool>(nameof(IsTodayHighlighted));
/// <summary>
/// Defines the <see cref="SelectedDate"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, DateTime?> SelectedDateProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(SelectedDate),
o => o.SelectedDate,
(o, v) => o.SelectedDate = v,
enableDataValidation: true,
defaultBindingMode:BindingMode.TwoWay);
/// <summary>
/// Defines the <see cref="SelectedDateFormat"/> property.
/// </summary>
public static readonly StyledProperty<CalendarDatePickerFormat> SelectedDateFormatProperty =
AvaloniaProperty.Register<CalendarDatePicker, CalendarDatePickerFormat>(
nameof(SelectedDateFormat),
defaultValue: CalendarDatePickerFormat.Short,
validate: IsValidSelectedDateFormat);
/// <summary>
/// Defines the <see cref="CustomDateFormatString"/> property.
/// </summary>
public static readonly StyledProperty<string> CustomDateFormatStringProperty =
AvaloniaProperty.Register<CalendarDatePicker, string>(
nameof(CustomDateFormatString),
defaultValue: "d",
validate: IsValidDateFormatString);
/// <summary>
/// Defines the <see cref="Text"/> property.
/// </summary>
public static readonly DirectProperty<CalendarDatePicker, string?> TextProperty =
AvaloniaProperty.RegisterDirect<CalendarDatePicker, string?>(
nameof(Text),
o => o.Text,
(o, v) => o.Text = v);
/// <summary>
/// Defines the <see cref="Watermark"/> property.
/// </summary>
public static readonly StyledProperty<string?> WatermarkProperty =
TextBox.WatermarkProperty.AddOwner<CalendarDatePicker>();
/// <summary>
/// Defines the <see cref="UseFloatingWatermark"/> property.
/// </summary>
public static readonly StyledProperty<bool> UseFloatingWatermarkProperty =
TextBox.UseFloatingWatermarkProperty.AddOwner<CalendarDatePicker>();
/// <summary>
/// Defines the <see cref="HorizontalContentAlignment"/> property.
/// </summary>
public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty =
ContentControl.HorizontalContentAlignmentProperty.AddOwner<CalendarDatePicker>();
/// <summary>
/// Defines the <see cref="VerticalContentAlignment"/> property.
/// </summary>
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner<CalendarDatePicker>();
/// <summary>
/// Gets a collection of dates that are marked as not selectable.
/// </summary>
/// <value>
/// A collection of dates that cannot be selected. The default value is
/// an empty collection.
/// </value>
public CalendarBlackoutDatesCollection? BlackoutDates { get; private set; }
/// <summary>
/// Gets or sets the date to display.
/// </summary>
/// <value>
/// The date to display. The default is <see cref="DateTime.Today" />.
/// </value>
/// <exception cref="System.ArgumentOutOfRangeException">
/// The specified date is not in the range defined by
/// <see cref="CalendarDatePicker.DisplayDateStart" />
/// and
/// <see cref="CalendarDatePicker.DisplayDateEnd" />.
/// </exception>
public DateTime DisplayDate
{
get => _displayDate;
set => SetAndRaise(DisplayDateProperty, ref _displayDate, value);
}
/// <summary>
/// Gets or sets the first date to be displayed.
/// </summary>
/// <value>The first date to display.</value>
public DateTime? DisplayDateStart
{
get => _displayDateStart;
set => SetAndRaise(DisplayDateStartProperty, ref _displayDateStart, value);
}
/// <summary>
/// Gets or sets the last date to be displayed.
/// </summary>
/// <value>The last date to display.</value>
public DateTime? DisplayDateEnd
{
get => _displayDateEnd;
set => SetAndRaise(DisplayDateEndProperty, ref _displayDateEnd, value);
}
/// <summary>
/// Gets or sets the day that is considered the beginning of the week.
/// </summary>
/// <value>
/// A <see cref="T:System.DayOfWeek" /> representing the beginning of
/// the week. The default is <see cref="F:System.DayOfWeek.Sunday" />.
/// </value>
public DayOfWeek FirstDayOfWeek
{
get => GetValue(FirstDayOfWeekProperty);
set => SetValue(FirstDayOfWeekProperty, value);
}
/// <summary>
/// Gets or sets a value indicating whether the drop-down
/// <see cref="T:Avalonia.Controls.Calendar" /> is open or closed.
/// </summary>
/// <value>
/// True if the <see cref="T:Avalonia.Controls.Calendar" /> is
/// open; otherwise, false. The default is false.
/// </value>
public bool IsDropDownOpen
{
get => _isDropDownOpen;
set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value);
}
/// <summary>
/// Gets or sets a value indicating whether the current date will be
/// highlighted.
/// </summary>
/// <value>
/// True if the current date is highlighted; otherwise, false. The
/// default is true.
/// </value>
public bool IsTodayHighlighted
{
get => GetValue(IsTodayHighlightedProperty);
set => SetValue(IsTodayHighlightedProperty, value);
}
/// <summary>
/// Gets or sets the currently selected date.
/// </summary>
/// <value>
/// The date currently selected. The default is null.
/// </value>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// The specified date is not in the range defined by
/// <see cref="CalendarDatePicker.DisplayDateStart" />
/// and
/// <see cref="CalendarDatePicker.DisplayDateEnd" />,
/// or the specified date is in the
/// <see cref="CalendarDatePicker.BlackoutDates" />
/// collection.
/// </exception>
public DateTime? SelectedDate
{
get => _selectedDate;
set => SetAndRaise(SelectedDateProperty, ref _selectedDate, value);
}
/// <summary>
/// Gets or sets the format that is used to display the selected date.
/// </summary>
/// <value>
/// The format that is used to display the selected date. The default is
/// <see cref="CalendarDatePickerFormat.Short" />.
/// </value>
/// <exception cref="ArgumentOutOfRangeException">
/// An specified format is not valid.
/// </exception>
public CalendarDatePickerFormat SelectedDateFormat
{
get => GetValue(SelectedDateFormatProperty);
set => SetValue(SelectedDateFormatProperty, value);
}
public string CustomDateFormatString
{
get => GetValue(CustomDateFormatStringProperty);
set => SetValue(CustomDateFormatStringProperty, value);
}
/// <summary>
/// Gets or sets the text that is displayed by the <see cref="CalendarDatePicker" />.
/// </summary>
/// <value>
/// The text displayed by the <see cref="CalendarDatePicker" />.
/// </value>
/// <exception cref="FormatException">
/// The text entered cannot be parsed to a valid date, and the exception
/// is not suppressed.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// The text entered parses to a date that is not selectable.
/// </exception>
public string? Text
{
get => _text;
set => SetAndRaise(TextProperty, ref _text, value);
}
/// <inheritdoc cref="TextBox.Watermark"/>
public string? Watermark
{
get => GetValue(WatermarkProperty);
set => SetValue(WatermarkProperty, value);
}
/// <inheritdoc cref="TextBox.UseFloatingWatermark"/>
public bool UseFloatingWatermark
{
get => GetValue(UseFloatingWatermarkProperty);
set => SetValue(UseFloatingWatermarkProperty, value);
}
/// <summary>
/// Gets or sets the horizontal alignment of the content within the control.
/// </summary>
public HorizontalAlignment HorizontalContentAlignment
{
get => GetValue(HorizontalContentAlignmentProperty);
set => SetValue(HorizontalContentAlignmentProperty, value);
}
/// <summary>
/// Gets or sets the vertical alignment of the content within the control.
/// </summary>
public VerticalAlignment VerticalContentAlignment
{
get => GetValue(VerticalContentAlignmentProperty);
set => SetValue(VerticalContentAlignmentProperty, value);
}
}
}

797
src/Avalonia.Controls/Calendar/CalendarDatePicker.cs → src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs

File diff suppressed because it is too large

87
src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerDateValidationErrorEventArgs.cs

@ -0,0 +1,87 @@
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System;
namespace Avalonia.Controls
{
/// <summary>
/// Provides data for the
/// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event.
/// </summary>
public class CalendarDatePickerDateValidationErrorEventArgs : EventArgs
{
private bool _throwException;
/// <summary>
/// Initializes a new instance of the
/// <see cref="T:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs" />
/// class.
/// </summary>
/// <param name="exception">
/// The initial exception from the
/// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event.
/// </param>
/// <param name="text">
/// The text that caused the
/// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event.
/// </param>
public CalendarDatePickerDateValidationErrorEventArgs(Exception exception, string text)
{
Text = text;
Exception = exception;
}
/// <summary>
/// Gets the initial exception associated with the
/// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event.
/// </summary>
/// <value>
/// The exception associated with the validation failure.
/// </value>
public Exception Exception { get; private set; }
/// <summary>
/// Gets the text that caused the
/// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event.
/// </summary>
/// <value>
/// The text that caused the validation failure.
/// </value>
public string Text { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether
/// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
/// should be thrown.
/// </summary>
/// <value>
/// True if the exception should be thrown; otherwise, false.
/// </value>
/// <exception cref="T:System.ArgumentException">
/// If set to true and
/// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
/// is null.
/// </exception>
public bool ThrowException
{
get => _throwException;
set
{
if (value && Exception == null)
{
throw new ArgumentException("Cannot Throw Null Exception");
}
_throwException = value;
}
}
}
}

31
src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerFormat.cs

@ -0,0 +1,31 @@
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
namespace Avalonia.Controls
{
/// <summary>
/// Specifies date formats for a
/// <see cref="T:Avalonia.Controls.CalendarDatePicker" />.
/// </summary>
public enum CalendarDatePickerFormat
{
/// <summary>
/// Specifies that the date should be displayed using unabbreviated days
/// of the week and month names.
/// </summary>
Long = 0,
/// <summary>
/// Specifies that the date should be displayed using abbreviated days
/// of the week and month names.
/// </summary>
Short = 1,
/// <summary>
/// Specifies that the date should be displayed using a custom format string.
/// </summary>
Custom = 2
}
}

4
src/Avalonia.Controls/MenuBase.cs

@ -18,8 +18,8 @@ namespace Avalonia.Controls
/// <summary>
/// Defines the <see cref="IsOpen"/> property.
/// </summary>
public static readonly DirectProperty<Menu, bool> IsOpenProperty =
AvaloniaProperty.RegisterDirect<Menu, bool>(
public static readonly DirectProperty<MenuBase, bool> IsOpenProperty =
AvaloniaProperty.RegisterDirect<MenuBase, bool>(
nameof(IsOpen),
o => o.IsOpen);

4
src/Avalonia.Controls/MenuItem.cs

@ -85,13 +85,13 @@ namespace Avalonia.Controls
/// Defines the <see cref="PointerEnterItem"/> event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerEnterItemEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>(nameof(PointerEnterItem), RoutingStrategies.Bubble);
RoutedEvent.Register<MenuItem, PointerEventArgs>(nameof(PointerEnterItem), RoutingStrategies.Bubble);
/// <summary>
/// Defines the <see cref="PointerLeaveItem"/> event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerLeaveItemEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>(nameof(PointerLeaveItem), RoutingStrategies.Bubble);
RoutedEvent.Register<MenuItem, PointerEventArgs>(nameof(PointerLeaveItem), RoutingStrategies.Bubble);
/// <summary>
/// Defines the <see cref="SubmenuOpened"/> event.

4
src/Avalonia.Controls/NativeMenuItemBase.cs

@ -11,8 +11,8 @@ namespace Avalonia.Controls
}
public static readonly DirectProperty<NativeMenuItem, NativeMenu?> ParentProperty =
AvaloniaProperty.RegisterDirect<NativeMenuItem, NativeMenu?>("Parent", o => o.Parent, (o, v) => o.Parent = v);
public static readonly DirectProperty<NativeMenuItemBase, NativeMenu?> ParentProperty =
AvaloniaProperty.RegisterDirect<NativeMenuItemBase, NativeMenu?>("Parent", o => o.Parent, (o, v) => o.Parent = v);
public NativeMenu? Parent
{

4
src/Avalonia.Controls/RepeatButton.cs

@ -13,13 +13,13 @@ namespace Avalonia.Controls
/// Defines the <see cref="Interval"/> property.
/// </summary>
public static readonly StyledProperty<int> IntervalProperty =
AvaloniaProperty.Register<Button, int>(nameof(Interval), 100);
AvaloniaProperty.Register<RepeatButton, int>(nameof(Interval), 100);
/// <summary>
/// Defines the <see cref="Delay"/> property.
/// </summary>
public static readonly StyledProperty<int> DelayProperty =
AvaloniaProperty.Register<Button, int>(nameof(Delay), 300);
AvaloniaProperty.Register<RepeatButton, int>(nameof(Delay), 300);
private DispatcherTimer? _repeatTimer;

110
src/Avalonia.Controls/TextBox.cs

@ -245,23 +245,19 @@ namespace Avalonia.Controls
public bool AcceptsReturn
{
get { return GetValue(AcceptsReturnProperty); }
set { SetValue(AcceptsReturnProperty, value); }
get => GetValue(AcceptsReturnProperty);
set => SetValue(AcceptsReturnProperty, value);
}
public bool AcceptsTab
{
get { return GetValue(AcceptsTabProperty); }
set { SetValue(AcceptsTabProperty, value); }
get => GetValue(AcceptsTabProperty);
set => SetValue(AcceptsTabProperty, value);
}
public int CaretIndex
{
get
{
return _caretIndex;
}
get => _caretIndex;
set
{
value = CoerceCaretIndex(value);
@ -277,8 +273,8 @@ namespace Avalonia.Controls
public bool IsReadOnly
{
get { return GetValue(IsReadOnlyProperty); }
set { SetValue(IsReadOnlyProperty, value); }
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
public char PasswordChar
@ -307,11 +303,7 @@ namespace Avalonia.Controls
public int SelectionStart
{
get
{
return _selectionStart;
}
get => _selectionStart;
set
{
value = CoerceCaretIndex(value);
@ -331,11 +323,7 @@ namespace Avalonia.Controls
public int SelectionEnd
{
get
{
return _selectionEnd;
}
get => _selectionEnd;
set
{
value = CoerceCaretIndex(value);
@ -355,14 +343,14 @@ namespace Avalonia.Controls
public int MaxLength
{
get { return GetValue(MaxLengthProperty); }
set { SetValue(MaxLengthProperty, value); }
get => GetValue(MaxLengthProperty);
set => SetValue(MaxLengthProperty, value);
}
public int MaxLines
{
get { return GetValue(MaxLinesProperty); }
set { SetValue(MaxLinesProperty, value); }
get => GetValue(MaxLinesProperty);
set => SetValue(MaxLinesProperty, value);
}
/// <summary>
@ -377,7 +365,7 @@ namespace Avalonia.Controls
[Content]
public string? Text
{
get { return _text; }
get => _text;
set
{
if (!_ignoreTextChanges)
@ -401,7 +389,7 @@ namespace Avalonia.Controls
public string SelectedText
{
get { return GetSelection(); }
get => GetSelection();
set
{
if (string.IsNullOrEmpty(value))
@ -422,8 +410,8 @@ namespace Avalonia.Controls
/// </summary>
public HorizontalAlignment HorizontalContentAlignment
{
get { return GetValue(HorizontalContentAlignmentProperty); }
set { SetValue(HorizontalContentAlignmentProperty, value); }
get => GetValue(HorizontalContentAlignmentProperty);
set => SetValue(HorizontalContentAlignmentProperty, value);
}
/// <summary>
@ -431,50 +419,58 @@ namespace Avalonia.Controls
/// </summary>
public VerticalAlignment VerticalContentAlignment
{
get { return GetValue(VerticalContentAlignmentProperty); }
set { SetValue(VerticalContentAlignmentProperty, value); }
get => GetValue(VerticalContentAlignmentProperty);
set => SetValue(VerticalContentAlignmentProperty, value);
}
public TextAlignment TextAlignment
{
get { return GetValue(TextAlignmentProperty); }
set { SetValue(TextAlignmentProperty, value); }
get => GetValue(TextAlignmentProperty);
set => SetValue(TextAlignmentProperty, value);
}
/// <summary>
/// Gets or sets the placeholder or descriptive text that is displayed even if the <see cref="Text"/>
/// property is not yet set.
/// </summary>
public string? Watermark
{
get { return GetValue(WatermarkProperty); }
set { SetValue(WatermarkProperty, value); }
get => GetValue(WatermarkProperty);
set => SetValue(WatermarkProperty, value);
}
/// <summary>
/// Gets or sets a value indicating whether the <see cref="Watermark"/> will still be shown above the
/// <see cref="Text"/> even after a text value is set.
/// </summary>
public bool UseFloatingWatermark
{
get { return GetValue(UseFloatingWatermarkProperty); }
set { SetValue(UseFloatingWatermarkProperty, value); }
get => GetValue(UseFloatingWatermarkProperty);
set => SetValue(UseFloatingWatermarkProperty, value);
}
public object InnerLeftContent
{
get { return GetValue(InnerLeftContentProperty); }
set { SetValue(InnerLeftContentProperty, value); }
get => GetValue(InnerLeftContentProperty);
set => SetValue(InnerLeftContentProperty, value);
}
public object InnerRightContent
{
get { return GetValue(InnerRightContentProperty); }
set { SetValue(InnerRightContentProperty, value); }
get => GetValue(InnerRightContentProperty);
set => SetValue(InnerRightContentProperty, value);
}
public bool RevealPassword
{
get { return GetValue(RevealPasswordProperty); }
set { SetValue(RevealPasswordProperty, value); }
get => GetValue(RevealPasswordProperty);
set => SetValue(RevealPasswordProperty, value);
}
public TextWrapping TextWrapping
{
get { return GetValue(TextWrappingProperty); }
set { SetValue(TextWrappingProperty, value); }
get => GetValue(TextWrappingProperty);
set => SetValue(TextWrappingProperty, value);
}
/// <summary>
@ -482,8 +478,8 @@ namespace Avalonia.Controls
/// </summary>
public string NewLine
{
get { return _newLine; }
set { SetAndRaise(NewLineProperty, ref _newLine, value); }
get => _newLine;
set => SetAndRaise(NewLineProperty, ref _newLine, value);
}
/// <summary>
@ -499,8 +495,8 @@ namespace Avalonia.Controls
/// </summary>
public bool CanCut
{
get { return _canCut; }
private set { SetAndRaise(CanCutProperty, ref _canCut, value); }
get => _canCut;
private set => SetAndRaise(CanCutProperty, ref _canCut, value);
}
/// <summary>
@ -508,8 +504,8 @@ namespace Avalonia.Controls
/// </summary>
public bool CanCopy
{
get { return _canCopy; }
private set { SetAndRaise(CanCopyProperty, ref _canCopy, value); }
get => _canCopy;
private set => SetAndRaise(CanCopyProperty, ref _canCopy, value);
}
/// <summary>
@ -517,8 +513,8 @@ namespace Avalonia.Controls
/// </summary>
public bool CanPaste
{
get { return _canPaste; }
private set { SetAndRaise(CanPasteProperty, ref _canPaste, value); }
get => _canPaste;
private set => SetAndRaise(CanPasteProperty, ref _canPaste, value);
}
/// <summary>
@ -526,13 +522,13 @@ namespace Avalonia.Controls
/// </summary>
public bool IsUndoEnabled
{
get { return GetValue(IsUndoEnabledProperty); }
set { SetValue(IsUndoEnabledProperty, value); }
get => GetValue(IsUndoEnabledProperty);
set => SetValue(IsUndoEnabledProperty, value);
}
public int UndoLimit
{
get { return _undoRedoHelper.Limit; }
get => _undoRedoHelper.Limit;
set
{
if (_undoRedoHelper.Limit != value)
@ -1554,7 +1550,7 @@ namespace Avalonia.Controls
UndoRedoState UndoRedoHelper<UndoRedoState>.IUndoRedoHost.UndoRedoState
{
get { return new UndoRedoState(Text, CaretIndex); }
get => new UndoRedoState(Text, CaretIndex);
set
{
Text = value.Text;

17
src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml

@ -587,9 +587,24 @@
<StaticResource x:Key="SplitViewLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<!-- Resources for CalendarDatePicker.xaml -->
<StaticResource x:Key="CalendarDatePickerBackground" ResourceKey="SystemControlBackgroundAltMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CalendarDatePickerForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerCalendarGlyphForeground" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<StaticResource x:Key="CalendarDatePickerCalendarGlyphForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerTextForeground" ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerTextForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerTextForegroundSelected" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CalendarDatePickerHeaderForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackground" ResourceKey="SystemControlBackgroundAltMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundPointerOver" ResourceKey="SystemControlPageBackgroundAltMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundPressed" ResourceKey="SystemControlBackgroundBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundFocused" ResourceKey="SystemControlHighlightListAccentLowBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumHighBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushPressed" ResourceKey="SystemControlHighlightBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushDisabled" ResourceKey="SystemControlDisabledBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<Thickness x:Key="CalendarDatePickerBorderThemeThickness">1</Thickness>
<!-- Resources for FlyoutPresenter.xaml -->

17
src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml

@ -581,9 +581,24 @@
<StaticResource x:Key="SplitViewLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<!-- Resources for CalendarDatePicker.xaml -->
<StaticResource x:Key="CalendarDatePickerBackground" ResourceKey="SystemControlBackgroundAltMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CalendarDatePickerForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerCalendarGlyphForeground" ResourceKey="SystemControlForegroundBaseMediumHighBrush" />
<StaticResource x:Key="CalendarDatePickerCalendarGlyphForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerTextForeground" ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerTextForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerTextForegroundSelected" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="CalendarDatePickerHeaderForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackground" ResourceKey="SystemControlBackgroundAltMediumLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundPointerOver" ResourceKey="SystemControlPageBackgroundAltMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundPressed" ResourceKey="SystemControlBackgroundBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerBackgroundFocused" ResourceKey="SystemControlHighlightListAccentLowBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumHighBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushPressed" ResourceKey="SystemControlHighlightBaseMediumBrush" />
<StaticResource x:Key="CalendarDatePickerBorderBrushDisabled" ResourceKey="SystemControlDisabledBaseLowBrush" />
<StaticResource x:Key="CalendarDatePickerLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<Thickness x:Key="CalendarDatePickerBorderThemeThickness">1</Thickness>
<!-- Resources for FlyoutPresenter.xaml -->

252
src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml

@ -1,10 +1,3 @@
<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=netstandard"
@ -18,131 +11,172 @@
</Design.PreviewWith>
<Styles.Resources>
<sys:Double x:Key="CalendarDatePickerCurrentDayFontSize">12</sys:Double>
<x:Double x:Key="CalendarDatePickerCurrentDayFontSize">12</x:Double>
<x:Double x:Key="CalendarDatePickerMinHeight">32</x:Double>
</Styles.Resources>
<Style Selector="CalendarDatePicker">
<Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackground}"/>
<Setter Property="Foreground" Value="{DynamicResource CalendarDatePickerForeground}"/>
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrush}"/>
<Setter Property="BorderThickness" Value="{DynamicResource CalendarDatePickerBorderThemeThickness}"/>
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="MinHeight" Value="{DynamicResource CalendarDatePickerMinHeight}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="4"/>
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
<Grid ColumnDefinitions="*,Auto">
<Panel x:Name="LayoutRoot"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Border x:Name="Background"
CornerRadius="{TemplateBinding CornerRadius}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}" />
<Grid ColumnDefinitions="*,Auto">
<TextBox Name="PART_TextBox"
Foreground="{TemplateBinding Foreground}"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
CornerRadius="{TemplateBinding CornerRadius}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Watermark="{TemplateBinding Watermark}"
UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Grid.Column="0" />
<Button Name="PART_Button"
Grid.Column="1"
Focusable="False" />
<Popup Name="PART_Popup"
PlacementTarget="{TemplateBinding}"
IsLightDismissEnabled="True">
<Calendar Name="PART_Calendar"
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}"
SelectedDate="{TemplateBinding SelectedDate, Mode=TwoWay}"
DisplayDate="{TemplateBinding DisplayDate}"
DisplayDateStart="{TemplateBinding DisplayDateStart}"
DisplayDateEnd="{TemplateBinding DisplayDateEnd}" />
</Popup>
</Grid>
</Panel>
</DataValidationErrors>
</ControlTemplate>
</Setter>
</Style>
<!-- Normal State -->
<Style Selector="CalendarDatePicker /template/ Button#PART_Button">
<Setter Property="TextElement.Foreground" Value="{DynamicResource CalendarDatePickerCalendarGlyphForeground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="2,0,4,0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Width" Value="20" />
<Setter Property="Template">
<ControlTemplate>
<Grid Height="24"
Width="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0"
ColumnDefinitions="*,*,*,*"
RowDefinitions="23*,19*,19*,19*"
ClipToBounds="False">
<Border Name="Background"
Margin="0,-1,0,0"
Grid.ColumnSpan="4"
Grid.Row="1"
Grid.RowSpan="3"
BorderThickness="0.5,0,0.5,0.5"
BorderBrush="{TemplateBinding Foreground}"
CornerRadius="0,0,2,2" />
<Border Grid.ColumnSpan="4"
Grid.RowSpan="1"
BorderBrush="{TemplateBinding Foreground}"
BorderThickness="0.5"
CornerRadius="2,2,0,0" />
<TextBlock Margin="0,-1,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3"
Foreground="{TemplateBinding Foreground}"
FontSize="{DynamicResource CalendarDatePickerCurrentDayFontSize}"
Text="{Binding Source={x:Static sys:DateTime.Today}, Path=Day}" />
<Ellipse HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{TemplateBinding Foreground}"
StrokeThickness="0"
Grid.ColumnSpan="4"
Width="3"
Height="3" />
</Grid>
</ControlTemplate>
</Setter>
</Style>
<Grid.Styles>
<!-- Pressed State -->
<Style Selector="CalendarDatePicker:pressed /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundPressed}" />
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushPressed}" />
</Style>
<Style Selector="Button.CalendarDropDown">
<Setter Property="Template">
<ControlTemplate>
<Grid Height="24"
Width="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0"
ColumnDefinitions="*,*,*,*"
RowDefinitions="23*,19*,19*,19*"
ClipToBounds="False">
<!-- Pointer-over State -->
<Style Selector="CalendarDatePicker:pointerover /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundPointerOver}" />
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushPointerOver}" />
</Style>
<Border Name="Highlight"
Margin="-1"
Grid.ColumnSpan="4"
Grid.Row="0"
Grid.RowSpan="4"
BorderThickness="1"
BorderBrush="{DynamicResource SystemAccentColor}" />
<Border Name="Background"
Margin="0,-1,0,0"
Grid.ColumnSpan="4"
Grid.Row="1"
Grid.RowSpan="3"
BorderThickness="1"
BorderBrush="{DynamicResource SystemControlForegroundBaseMediumBrush}"
CornerRadius=".5" />
<Rectangle Grid.ColumnSpan="4"
Grid.RowSpan="1"
StrokeThickness="1"
Stroke="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Fill="{DynamicResource SystemAccentColor}">
</Rectangle>
<TextBlock Margin="0,-1,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3"
FontSize="{DynamicResource CalendarDatePickerCurrentDayFontSize}"
Text="{Binding Source={x:Static sys:DateTime.Today}, Path=Day}"/>
<!-- Disabled State -->
<Style Selector="CalendarDatePicker:disabled /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushDisabled}" />
</Style>
<Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource SystemControlBackgroundChromeBlackHighBrush}" StrokeThickness="0" Grid.ColumnSpan="4" Width="3" Height="3"/>
</Grid>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="CalendarDatePicker:disabled /template/ Button#PART_Button">
<Setter Property="TextElement.Foreground" Value="{DynamicResource CalendarDatePickerCalendarGlyphForegroundDisabled}" />
</Style>
<Style Selector="Button.CalendarDropDown /template/ Border#Highlight">
<Setter Property="IsVisible" Value="False"/>
</Style>
<Style Selector="Button.CalendarDropDown:pressed /template/ Border#Highlight">
<Setter Property="IsVisible" Value="True"/>
</Style>
<Style Selector="CalendarDatePicker:disabled /template/ TextBox#PART_TextBox:disabled /template/ Border#PART_BorderElement">
<!-- By default the TextBox has its own disabled state, override this to make the border background show through -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="Button.CalendarDropDown:pointerover /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource SystemAccentColorDark2}"/>
</Style>
</Grid.Styles>
<TextBox Name="PART_TextBox"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Padding="{TemplateBinding Padding}"
Watermark="{TemplateBinding Watermark}"
UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Grid.Column="0"/>
<Style Selector="CalendarDatePicker:disabled /template/ TextBox#PART_TextBox:disabled /template/ TextBlock#PART_Watermark,
CalendarDatePicker:disabled /template/ TextBox#PART_TextBox:disabled /template/ TextBlock#PART_FloatingWatermark">
<Setter Property="TextElement.Foreground" Value="{DynamicResource CalendarDatePickerTextForegroundDisabled}" />
</Style>
<Button Name="PART_Button"
Grid.Column="1"
Width="20"
Classes="CalendarDropDown"
Foreground="{TemplateBinding Foreground}"
Background="Transparent"
BorderThickness="0"
Margin="2,0,2,0"
Padding="0"
ClipToBounds="False"
Focusable="False"/>
<!-- Focused State -->
<Style Selector="CalendarDatePicker:focus-within:not(CalendarDatePicker:focus) /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundFocused}"/>
<Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}"/>
<Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThicknessFocused}" />
</Style>
<Popup Name="PART_Popup"
PlacementTarget="{TemplateBinding}"
IsLightDismissEnabled="True">
<Calendar Name="PART_Calendar"
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}"
SelectedDate="{TemplateBinding SelectedDate, Mode=TwoWay}"
DisplayDate="{TemplateBinding DisplayDate}"
DisplayDateStart="{TemplateBinding DisplayDateStart}"
DisplayDateEnd="{TemplateBinding DisplayDateEnd}" />
</Popup>
</Grid>
</DataValidationErrors>
</ControlTemplate>
</Setter>
<Style Selector="CalendarDatePicker /template/ TextBox#PART_TextBox:focus /template/ Border#PART_BorderElement">
<!-- By default the TextBox has its own focused state, override this to disable it here -->
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style Selector="CalendarDatePicker:error TextBox /template/ Border#PART_BorderElement">
<!-- Error State -->
<Style Selector="CalendarDatePicker:error /template/ Border#Background">
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlErrorTextForegroundBrush}"/>
</Style>
</Styles>

97
tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs

@ -321,6 +321,103 @@ namespace Avalonia.Base.UnitTests.Layout
Times.Once);
}
[Fact]
public void Making_Control_Invisible_Should_Invalidate_Parent_Measure()
{
Border child;
var target = new StackPanel
{
Children =
{
(child = new Border
{
Width = 100,
}),
}
};
target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
target.Arrange(new Rect(target.DesiredSize));
Assert.True(target.IsMeasureValid);
Assert.True(target.IsArrangeValid);
Assert.True(child.IsMeasureValid);
Assert.True(child.IsArrangeValid);
child.IsVisible = false;
Assert.False(target.IsMeasureValid);
Assert.False(target.IsArrangeValid);
Assert.True(child.IsMeasureValid);
Assert.True(child.IsArrangeValid);
}
[Fact]
public void Making_Control_Visible_Should_Invalidate_Own_And_Parent_Measure()
{
Border child;
var target = new StackPanel
{
Children =
{
(child = new Border
{
Width = 100,
IsVisible = false,
}),
}
};
target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
target.Arrange(new Rect(target.DesiredSize));
Assert.True(target.IsMeasureValid);
Assert.True(target.IsArrangeValid);
Assert.True(child.IsMeasureValid);
Assert.False(child.IsArrangeValid);
child.IsVisible = true;
Assert.False(target.IsMeasureValid);
Assert.False(target.IsArrangeValid);
Assert.False(child.IsMeasureValid);
Assert.False(child.IsArrangeValid);
}
[Fact]
public void Measuring_Invisible_Control_Should_Not_Invalidate_Parent_Measure()
{
Border child;
var target = new StackPanel
{
Children =
{
(child = new Border
{
Width = 100,
}),
}
};
target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
target.Arrange(new Rect(target.DesiredSize));
Assert.True(target.IsMeasureValid);
Assert.True(target.IsArrangeValid);
Assert.Equal(new Size(100, 0), child.DesiredSize);
child.IsVisible = false;
Assert.Equal(default, child.DesiredSize);
target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
target.Arrange(new Rect(target.DesiredSize));
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
Assert.True(target.IsMeasureValid);
Assert.True(target.IsArrangeValid);
Assert.Equal(default, child.DesiredSize);
}
private class TestLayoutable : Layoutable
{
public Size ArrangeSize { get; private set; }

Loading…
Cancel
Save