committed by
GitHub
18 changed files with 1133 additions and 777 deletions
@ -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); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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 |
|||
} |
|||
} |
|||
Loading…
Reference in new issue