Browse Source

Merge pull request #7958 from robloo/calendar-date-picker

Refactor CalendarDatePicker and Update Fluent Style
pull/8163/head
Max Katz 4 years ago
committed by GitHub
parent
commit
3290780ead
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
  2. 6
      src/Avalonia.Controls/Button.cs
  3. 303
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs
  4. 797
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs
  5. 87
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerDateValidationErrorEventArgs.cs
  6. 31
      src/Avalonia.Controls/CalendarDatePicker/CalendarDatePickerFormat.cs
  7. 110
      src/Avalonia.Controls/TextBox.cs
  8. 17
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
  9. 17
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
  10. 252
      src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml

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"

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
}
}

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>

Loading…
Cancel
Save