Browse Source

Rename existing DatePicker control

pull/4113/head
amwx 6 years ago
parent
commit
0863b29d09
  1. 3
      samples/ControlCatalog/MainView.xaml
  2. 18
      samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
  3. 14
      samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml.cs
  4. 4
      src/Avalonia.Controls/Calendar/Calendar.cs
  5. 134
      src/Avalonia.Controls/Calendar/CalendarDatePicker.cs
  6. 4
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  7. 4
      src/Avalonia.Themes.Default/CalendarDatePicker.xaml
  8. 2
      src/Avalonia.Themes.Default/DefaultTheme.xaml
  9. 4
      src/Avalonia.Themes.Fluent/CalendarDatePicker.xaml
  10. 2
      src/Avalonia.Themes.Fluent/FluentTheme.xaml
  11. 14
      tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs

3
samples/ControlCatalog/MainView.xaml

@ -29,7 +29,8 @@
ScrollViewer.HorizontalScrollBarVisibility="Disabled"> ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<pages:DataGridPage/> <pages:DataGridPage/>
</TabItem> </TabItem>
<TabItem Header="DatePicker"><pages:DatePickerPage/></TabItem> <TabItem Header="CalendarDatePicker">
<pages:CalendarDatePickerPage/></TabItem>
<TabItem Header="Drag+Drop"><pages:DragAndDropPage/></TabItem> <TabItem Header="Drag+Drop"><pages:DragAndDropPage/></TabItem>
<TabItem Header="Expander"><pages:ExpanderPage/></TabItem> <TabItem Header="Expander"><pages:ExpanderPage/></TabItem>
<TabItem Header="Image" <TabItem Header="Image"

18
samples/ControlCatalog/Pages/DatePickerPage.xaml → samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml

@ -1,8 +1,8 @@
<UserControl xmlns="https://github.com/avaloniaui" <UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ControlCatalog.Pages.DatePickerPage"> x:Class="ControlCatalog.Pages.CalendarDatePickerPage">
<StackPanel Orientation="Vertical" Spacing="4"> <StackPanel Orientation="Vertical" Spacing="4">
<TextBlock Classes="h1">DatePicker</TextBlock> <TextBlock Classes="h1">CalendarDatePicker</TextBlock>
<TextBlock Classes="h2">A control for selecting dates with a calendar drop-down</TextBlock> <TextBlock Classes="h2">A control for selecting dates with a calendar drop-down</TextBlock>
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
@ -12,34 +12,34 @@
<StackPanel Orientation="Vertical" <StackPanel Orientation="Vertical"
Width="200"> Width="200">
<TextBlock Text="SelectedDateFormat: Short"/> <TextBlock Text="SelectedDateFormat: Short"/>
<DatePicker Name="DatePicker1" <CalendarDatePicker Name="DatePicker1"
SelectedDateFormat="Short" SelectedDateFormat="Short"
Margin="0,0,0,8"/> Margin="0,0,0,8"/>
<TextBlock Text="SelectedDateFormat: Long"/> <TextBlock Text="SelectedDateFormat: Long"/>
<DatePicker Name="DatePicker2" <CalendarDatePicker Name="DatePicker2"
SelectedDateFormat="Long" SelectedDateFormat="Long"
Margin="0,0,0,8"/> Margin="0,0,0,8"/>
<TextBlock Text="SelectedDateFormat: Custom"/> <TextBlock Text="SelectedDateFormat: Custom"/>
<DatePicker Name="DatePicker3" <CalendarDatePicker Name="DatePicker3"
SelectedDateFormat="Custom" SelectedDateFormat="Custom"
CustomDateFormatString="ddd, MMM d" CustomDateFormatString="ddd, MMM d"
Margin="0,0,0,8"/> Margin="0,0,0,8"/>
<TextBlock Text="Blackout Dates"/> <TextBlock Text="Blackout Dates"/>
<DatePicker Name="DatePicker4" <CalendarDatePicker Name="DatePicker4"
Margin="0,0,0,8"/> Margin="0,0,0,8"/>
<DatePicker Margin="0,0,0,8" <CalendarDatePicker Margin="0,0,0,8"
Watermark="Watermark"/> Watermark="Watermark"/>
<DatePicker Margin="0,0,0,8" <CalendarDatePicker Margin="0,0,0,8"
Name="DatePicker5" Name="DatePicker5"
Watermark="Floating Watermark" Watermark="Floating Watermark"
UseFloatingWatermark="True"/> UseFloatingWatermark="True"/>
<TextBlock Text="Disabled"/> <TextBlock Text="Disabled"/>
<DatePicker IsEnabled="False"/> <CalendarDatePicker IsEnabled="False"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

14
samples/ControlCatalog/Pages/DatePickerPage.xaml.cs → samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml.cs

@ -4,17 +4,17 @@ using System;
namespace ControlCatalog.Pages namespace ControlCatalog.Pages
{ {
public class DatePickerPage : UserControl public class CalendarDatePickerPage : UserControl
{ {
public DatePickerPage() public CalendarDatePickerPage()
{ {
InitializeComponent(); InitializeComponent();
var dp1 = this.FindControl<DatePicker>("DatePicker1"); var dp1 = this.FindControl<CalendarDatePicker>("DatePicker1");
var dp2 = this.FindControl<DatePicker>("DatePicker2"); var dp2 = this.FindControl<CalendarDatePicker>("DatePicker2");
var dp3 = this.FindControl<DatePicker>("DatePicker3"); var dp3 = this.FindControl<CalendarDatePicker>("DatePicker3");
var dp4 = this.FindControl<DatePicker>("DatePicker4"); var dp4 = this.FindControl<CalendarDatePicker>("DatePicker4");
var dp5 = this.FindControl<DatePicker>("DatePicker5"); var dp5 = this.FindControl<CalendarDatePicker>("DatePicker5");
dp1.SelectedDate = DateTime.Today; dp1.SelectedDate = DateTime.Today;
dp2.SelectedDate = DateTime.Today.AddDays(10); dp2.SelectedDate = DateTime.Today.AddDays(10);

4
src/Avalonia.Controls/Calendar/Calendar.cs

@ -998,10 +998,10 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets a value indicating whether DatePicker should change its /// Gets or sets a value indicating whether CalendarDatePicker should change its
/// DisplayDate because of a SelectedDate change on its Calendar. /// DisplayDate because of a SelectedDate change on its Calendar.
/// </summary> /// </summary>
internal bool DatePickerDisplayDateFlag { get; set; } internal bool CalendarDatePickerDisplayDateFlag { get; set; }
internal CalendarDayButton FindDayButtonFromDay(DateTime day) internal CalendarDayButton FindDayButtonFromDay(DateTime day)
{ {

134
src/Avalonia.Controls/Calendar/DatePicker.cs → src/Avalonia.Controls/Calendar/CalendarDatePicker.cs

@ -16,29 +16,29 @@ namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
/// Provides data for the /// Provides data for the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </summary> /// </summary>
public class DatePickerDateValidationErrorEventArgs : EventArgs public class CalendarDatePickerDateValidationErrorEventArgs : EventArgs
{ {
private bool _throwException; private bool _throwException;
/// <summary> /// <summary>
/// Initializes a new instance of the /// Initializes a new instance of the
/// <see cref="T:Avalonia.Controls.DatePickerDateValidationErrorEventArgs" /> /// <see cref="T:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs" />
/// class. /// class.
/// </summary> /// </summary>
/// <param name="exception"> /// <param name="exception">
/// The initial exception from the /// The initial exception from the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </param> /// </param>
/// <param name="text"> /// <param name="text">
/// The text that caused the /// The text that caused the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </param> /// </param>
public DatePickerDateValidationErrorEventArgs(Exception exception, string text) public CalendarDatePickerDateValidationErrorEventArgs(Exception exception, string text)
{ {
this.Text = text; this.Text = text;
this.Exception = exception; this.Exception = exception;
@ -46,7 +46,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets the initial exception associated with the /// Gets the initial exception associated with the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </summary> /// </summary>
/// <value> /// <value>
@ -56,7 +56,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets the text that caused the /// Gets the text that caused the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </summary> /// </summary>
/// <value> /// <value>
@ -66,7 +66,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets a value indicating whether /// Gets or sets a value indicating whether
/// <see cref="P:Avalonia.Controls.DatePickerDateValidationErrorEventArgs.Exception" /> /// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
/// should be thrown. /// should be thrown.
/// </summary> /// </summary>
/// <value> /// <value>
@ -74,7 +74,7 @@ namespace Avalonia.Controls
/// </value> /// </value>
/// <exception cref="T:System.ArgumentException"> /// <exception cref="T:System.ArgumentException">
/// If set to true and /// If set to true and
/// <see cref="P:Avalonia.Controls.DatePickerDateValidationErrorEventArgs.Exception" /> /// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
/// is null. /// is null.
/// </exception> /// </exception>
public bool ThrowException public bool ThrowException
@ -93,9 +93,9 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Specifies date formats for a /// Specifies date formats for a
/// <see cref="T:Avalonia.Controls.DatePicker" />. /// <see cref="T:Avalonia.Controls.CalendarDatePicker" />.
/// </summary> /// </summary>
public enum DatePickerFormat public enum CalendarDatePickerFormat
{ {
/// <summary> /// <summary>
/// Specifies that the date should be displayed using unabbreviated days /// Specifies that the date should be displayed using unabbreviated days
@ -115,7 +115,7 @@ namespace Avalonia.Controls
Custom = 2 Custom = 2
} }
public class DatePicker : TemplatedControl public class CalendarDatePicker : TemplatedControl
{ {
private const string ElementTextBox = "PART_TextBox"; private const string ElementTextBox = "PART_TextBox";
private const string ElementButton = "PART_Button"; private const string ElementButton = "PART_Button";
@ -154,59 +154,59 @@ namespace Avalonia.Controls
/// </value> /// </value>
public CalendarBlackoutDatesCollection BlackoutDates { get; private set; } public CalendarBlackoutDatesCollection BlackoutDates { get; private set; }
public static readonly DirectProperty<DatePicker, DateTime> DisplayDateProperty = public static readonly DirectProperty<CalendarDatePicker, DateTime> DisplayDateProperty =
AvaloniaProperty.RegisterDirect<DatePicker, DateTime>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime>(
nameof(DisplayDate), nameof(DisplayDate),
o => o.DisplayDate, o => o.DisplayDate,
(o, v) => o.DisplayDate = v); (o, v) => o.DisplayDate = v);
public static readonly DirectProperty<DatePicker, DateTime?> DisplayDateStartProperty = public static readonly DirectProperty<CalendarDatePicker, DateTime?> DisplayDateStartProperty =
AvaloniaProperty.RegisterDirect<DatePicker, DateTime?>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(DisplayDateStart), nameof(DisplayDateStart),
o => o.DisplayDateStart, o => o.DisplayDateStart,
(o, v) => o.DisplayDateStart = v); (o, v) => o.DisplayDateStart = v);
public static readonly DirectProperty<DatePicker, DateTime?> DisplayDateEndProperty = public static readonly DirectProperty<CalendarDatePicker, DateTime?> DisplayDateEndProperty =
AvaloniaProperty.RegisterDirect<DatePicker, DateTime?>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(DisplayDateEnd), nameof(DisplayDateEnd),
o => o.DisplayDateEnd, o => o.DisplayDateEnd,
(o, v) => o.DisplayDateEnd = v); (o, v) => o.DisplayDateEnd = v);
public static readonly StyledProperty<DayOfWeek> FirstDayOfWeekProperty = public static readonly StyledProperty<DayOfWeek> FirstDayOfWeekProperty =
AvaloniaProperty.Register<DatePicker, DayOfWeek>(nameof(FirstDayOfWeek)); AvaloniaProperty.Register<CalendarDatePicker, DayOfWeek>(nameof(FirstDayOfWeek));
public static readonly DirectProperty<DatePicker, bool> IsDropDownOpenProperty = public static readonly DirectProperty<CalendarDatePicker, bool> IsDropDownOpenProperty =
AvaloniaProperty.RegisterDirect<DatePicker, bool>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, bool>(
nameof(IsDropDownOpen), nameof(IsDropDownOpen),
o => o.IsDropDownOpen, o => o.IsDropDownOpen,
(o, v) => o.IsDropDownOpen = v); (o, v) => o.IsDropDownOpen = v);
public static readonly StyledProperty<bool> IsTodayHighlightedProperty = public static readonly StyledProperty<bool> IsTodayHighlightedProperty =
AvaloniaProperty.Register<DatePicker, bool>(nameof(IsTodayHighlighted)); AvaloniaProperty.Register<CalendarDatePicker, bool>(nameof(IsTodayHighlighted));
public static readonly DirectProperty<DatePicker, DateTime?> SelectedDateProperty = public static readonly DirectProperty<CalendarDatePicker, DateTime?> SelectedDateProperty =
AvaloniaProperty.RegisterDirect<DatePicker, DateTime?>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, DateTime?>(
nameof(SelectedDate), nameof(SelectedDate),
o => o.SelectedDate, o => o.SelectedDate,
(o, v) => o.SelectedDate = v); (o, v) => o.SelectedDate = v);
public static readonly StyledProperty<DatePickerFormat> SelectedDateFormatProperty = public static readonly StyledProperty<CalendarDatePickerFormat> SelectedDateFormatProperty =
AvaloniaProperty.Register<DatePicker, DatePickerFormat>( AvaloniaProperty.Register<CalendarDatePicker, CalendarDatePickerFormat>(
nameof(SelectedDateFormat), nameof(SelectedDateFormat),
defaultValue: DatePickerFormat.Short, defaultValue: CalendarDatePickerFormat.Short,
validate: IsValidSelectedDateFormat); validate: IsValidSelectedDateFormat);
public static readonly StyledProperty<string> CustomDateFormatStringProperty = public static readonly StyledProperty<string> CustomDateFormatStringProperty =
AvaloniaProperty.Register<DatePicker, string>( AvaloniaProperty.Register<CalendarDatePicker, string>(
nameof(CustomDateFormatString), nameof(CustomDateFormatString),
defaultValue: "d", defaultValue: "d",
validate: IsValidDateFormatString); validate: IsValidDateFormatString);
public static readonly DirectProperty<DatePicker, string> TextProperty = public static readonly DirectProperty<CalendarDatePicker, string> TextProperty =
AvaloniaProperty.RegisterDirect<DatePicker, string>( AvaloniaProperty.RegisterDirect<CalendarDatePicker, string>(
nameof(Text), nameof(Text),
o => o.Text, o => o.Text,
(o, v) => o.Text = v); (o, v) => o.Text = v);
public static readonly StyledProperty<string> WatermarkProperty = public static readonly StyledProperty<string> WatermarkProperty =
TextBox.WatermarkProperty.AddOwner<DatePicker>(); TextBox.WatermarkProperty.AddOwner<CalendarDatePicker>();
public static readonly StyledProperty<bool> UseFloatingWatermarkProperty = public static readonly StyledProperty<bool> UseFloatingWatermarkProperty =
TextBox.UseFloatingWatermarkProperty.AddOwner<DatePicker>(); TextBox.UseFloatingWatermarkProperty.AddOwner<CalendarDatePicker>();
/// <summary> /// <summary>
@ -218,9 +218,9 @@ namespace Avalonia.Controls
/// </value> /// </value>
/// <exception cref="T:System.ArgumentOutOfRangeException"> /// <exception cref="T:System.ArgumentOutOfRangeException">
/// The specified date is not in the range defined by /// The specified date is not in the range defined by
/// <see cref="P:Avalonia.Controls.DatePicker.DisplayDateStart" /> /// <see cref="P:Avalonia.Controls.CalendarDatePicker.DisplayDateStart" />
/// and /// and
/// <see cref="P:Avalonia.Controls.DatePicker.DisplayDateEnd" />. /// <see cref="P:Avalonia.Controls.CalendarDatePicker.DisplayDateEnd" />.
/// </exception> /// </exception>
public DateTime DisplayDate public DateTime DisplayDate
{ {
@ -320,7 +320,7 @@ namespace Avalonia.Controls
/// <exception cref="T:System.ArgumentOutOfRangeException"> /// <exception cref="T:System.ArgumentOutOfRangeException">
/// An specified format is not valid. /// An specified format is not valid.
/// </exception> /// </exception>
public DatePickerFormat SelectedDateFormat public CalendarDatePickerFormat SelectedDateFormat
{ {
get { return GetValue(SelectedDateFormatProperty); } get { return GetValue(SelectedDateFormatProperty); }
set { SetValue(SelectedDateFormatProperty, value); } set { SetValue(SelectedDateFormatProperty, value); }
@ -380,33 +380,33 @@ namespace Avalonia.Controls
/// Occurs when <see cref="P:Avalonia.Controls.DatePicker.Text" /> /// Occurs when <see cref="P:Avalonia.Controls.DatePicker.Text" />
/// is assigned a value that cannot be interpreted as a date. /// is assigned a value that cannot be interpreted as a date.
/// </summary> /// </summary>
public event EventHandler<DatePickerDateValidationErrorEventArgs> DateValidationError; public event EventHandler<CalendarDatePickerDateValidationErrorEventArgs> DateValidationError;
/// <summary> /// <summary>
/// Occurs when the /// Occurs when the
/// <see cref="P:Avalonia.Controls.DatePicker.SelectedDate" /> /// <see cref="P:Avalonia.Controls.CalendarDatePicker.SelectedDate" />
/// property is changed. /// property is changed.
/// </summary> /// </summary>
public event EventHandler<SelectionChangedEventArgs> SelectedDateChanged; public event EventHandler<SelectionChangedEventArgs> SelectedDateChanged;
static DatePicker() static CalendarDatePicker()
{ {
FocusableProperty.OverrideDefaultValue<DatePicker>(true); FocusableProperty.OverrideDefaultValue<CalendarDatePicker>(true);
DisplayDateProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnDisplayDateChanged(e)); DisplayDateProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnDisplayDateChanged(e));
DisplayDateStartProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnDisplayDateStartChanged(e)); DisplayDateStartProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnDisplayDateStartChanged(e));
DisplayDateEndProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnDisplayDateEndChanged(e)); DisplayDateEndProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnDisplayDateEndChanged(e));
IsDropDownOpenProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnIsDropDownOpenChanged(e)); IsDropDownOpenProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnIsDropDownOpenChanged(e));
SelectedDateProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnSelectedDateChanged(e)); SelectedDateProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnSelectedDateChanged(e));
SelectedDateFormatProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnSelectedDateFormatChanged(e)); SelectedDateFormatProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnSelectedDateFormatChanged(e));
CustomDateFormatStringProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnCustomDateFormatStringChanged(e)); CustomDateFormatStringProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnCustomDateFormatStringChanged(e));
TextProperty.Changed.AddClassHandler<DatePicker>((x,e) => x.OnTextChanged(e)); TextProperty.Changed.AddClassHandler<CalendarDatePicker>((x,e) => x.OnTextChanged(e));
} }
/// <summary> /// <summary>
/// Initializes a new instance of the /// Initializes a new instance of the
/// <see cref="T:Avalonia.Controls.DatePicker" /> class. /// <see cref="T:Avalonia.Controls.DatePicker" /> class.
/// </summary> /// </summary>
public DatePicker() public CalendarDatePicker()
{ {
FirstDayOfWeek = DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek; FirstDayOfWeek = DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek;
_defaultText = string.Empty; _defaultText = string.Empty;
@ -662,12 +662,12 @@ namespace Avalonia.Controls
// change is coming from the Calendar UI itself, so, we // change is coming from the Calendar UI itself, so, we
// shouldn't change the DisplayDate since it will automatically // shouldn't change the DisplayDate since it will automatically
// be changed by the Calendar // be changed by the Calendar
if ((day.Month != DisplayDate.Month || day.Year != DisplayDate.Year) && (_calendar == null || !_calendar.DatePickerDisplayDateFlag)) if ((day.Month != DisplayDate.Month || day.Year != DisplayDate.Year) && (_calendar == null || !_calendar.CalendarDatePickerDisplayDateFlag))
{ {
DisplayDate = day; DisplayDate = day;
} }
if(_calendar != null) if(_calendar != null)
_calendar.DatePickerDisplayDateFlag = false; _calendar.CalendarDatePickerDisplayDateFlag = false;
} }
else else
{ {
@ -707,7 +707,7 @@ namespace Avalonia.Controls
} }
private void OnCustomDateFormatStringChanged(AvaloniaPropertyChangedEventArgs e) private void OnCustomDateFormatStringChanged(AvaloniaPropertyChangedEventArgs e)
{ {
if(SelectedDateFormat == DatePickerFormat.Custom) if(SelectedDateFormat == CalendarDatePickerFormat.Custom)
{ {
OnDateFormatChanged(); OnDateFormatChanged();
} }
@ -752,15 +752,15 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Raises the /// Raises the
/// <see cref="E:Avalonia.Controls.DatePicker.DateValidationError" /> /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
/// event. /// event.
/// </summary> /// </summary>
/// <param name="e"> /// <param name="e">
/// A /// A
/// <see cref="T:Avalonia.Controls.DatePickerDateValidationErrorEventArgs" /> /// <see cref="T:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs" />
/// that contains the event data. /// that contains the event data.
/// </param> /// </param>
protected virtual void OnDateValidationError(DatePickerDateValidationErrorEventArgs e) protected virtual void OnDateValidationError(CalendarDatePickerDateValidationErrorEventArgs e)
{ {
DateValidationError?.Invoke(this, e); DateValidationError?.Invoke(this, e);
} }
@ -959,7 +959,7 @@ namespace Avalonia.Controls
} }
else else
{ {
var dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException(nameof(text), "SelectedDate value is not valid."), text); var dateValidationError = new CalendarDatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException(nameof(text), "SelectedDate value is not valid."), text);
OnDateValidationError(dateValidationError); OnDateValidationError(dateValidationError);
if (dateValidationError.ThrowException) if (dateValidationError.ThrowException)
@ -970,7 +970,7 @@ namespace Avalonia.Controls
} }
catch (FormatException ex) catch (FormatException ex)
{ {
DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text); CalendarDatePickerDateValidationErrorEventArgs textParseError = new CalendarDatePickerDateValidationErrorEventArgs(ex, text);
OnDateValidationError(textParseError); OnDateValidationError(textParseError);
if (textParseError.ThrowException) if (textParseError.ThrowException)
@ -986,11 +986,11 @@ namespace Avalonia.Controls
switch (SelectedDateFormat) switch (SelectedDateFormat)
{ {
case DatePickerFormat.Short: case CalendarDatePickerFormat.Short:
return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.ShortDatePattern, dtfi)); return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.ShortDatePattern, dtfi));
case DatePickerFormat.Long: case CalendarDatePickerFormat.Long:
return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.LongDatePattern, dtfi)); return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.LongDatePattern, dtfi));
case DatePickerFormat.Custom: case CalendarDatePickerFormat.Custom:
return string.Format(CultureInfo.CurrentCulture, d.ToString(CustomDateFormatString, dtfi)); return string.Format(CultureInfo.CurrentCulture, d.ToString(CustomDateFormatString, dtfi));
} }
return null; return null;
@ -1118,12 +1118,12 @@ namespace Avalonia.Controls
switch (SelectedDateFormat) switch (SelectedDateFormat)
{ {
case DatePickerFormat.Long: case CalendarDatePickerFormat.Long:
{ {
watermarkText = string.Format(CultureInfo.CurrentCulture, watermarkFormat, dtfi.LongDatePattern.ToString()); watermarkText = string.Format(CultureInfo.CurrentCulture, watermarkFormat, dtfi.LongDatePattern.ToString());
break; break;
} }
case DatePickerFormat.Short: case CalendarDatePickerFormat.Short:
default: default:
{ {
watermarkText = string.Format(CultureInfo.CurrentCulture, watermarkFormat, dtfi.ShortDatePattern.ToString()); watermarkText = string.Format(CultureInfo.CurrentCulture, watermarkFormat, dtfi.ShortDatePattern.ToString());
@ -1139,11 +1139,11 @@ namespace Avalonia.Controls
} }
} }
private static bool IsValidSelectedDateFormat(DatePickerFormat value) private static bool IsValidSelectedDateFormat(CalendarDatePickerFormat value)
{ {
return value == DatePickerFormat.Long return value == CalendarDatePickerFormat.Long
|| value == DatePickerFormat.Short || value == CalendarDatePickerFormat.Short
|| value == DatePickerFormat.Custom; || value == CalendarDatePickerFormat.Custom;
} }
private static bool IsValidDateFormatString(string formatString) private static bool IsValidDateFormatString(string formatString)
{ {

4
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -909,7 +909,7 @@ namespace Avalonia.Controls.Primitives
case CalendarSelectionMode.SingleDate: case CalendarSelectionMode.SingleDate:
{ {
DateTime selectedDate = (DateTime)b.DataContext; DateTime selectedDate = (DateTime)b.DataContext;
Owner.DatePickerDisplayDateFlag = true; Owner.CalendarDatePickerDisplayDateFlag = true;
if (Owner.SelectedDates.Count == 0) if (Owner.SelectedDates.Count == 0)
{ {
Owner.SelectedDates.Add(selectedDate); Owner.SelectedDates.Add(selectedDate);
@ -981,7 +981,7 @@ namespace Avalonia.Controls.Primitives
} }
case CalendarSelectionMode.SingleDate: case CalendarSelectionMode.SingleDate:
{ {
Owner.DatePickerDisplayDateFlag = true; Owner.CalendarDatePickerDisplayDateFlag = true;
if (Owner.SelectedDates.Count == 0) if (Owner.SelectedDates.Count == 0)
{ {
Owner.SelectedDates.Add(selectedDate); Owner.SelectedDates.Add(selectedDate);

4
src/Avalonia.Themes.Fluent/DatePicker.xaml → src/Avalonia.Themes.Default/CalendarDatePicker.xaml

@ -8,7 +8,7 @@
<Styles xmlns="https://github.com/avaloniaui" <Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=netstandard"> xmlns:sys="clr-namespace:System;assembly=netstandard">
<Style Selector="DatePicker"> <Style Selector="CalendarDatePicker">
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/> <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
@ -119,7 +119,7 @@
</Setter> </Setter>
</Style> </Style>
<Style Selector="DatePicker:focus /template/ TextBox#PART_TextBox"> <Style Selector="CalendarDatePicker:focus /template/ TextBox#PART_TextBox">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style> </Style>

2
src/Avalonia.Themes.Default/DefaultTheme.xaml

@ -45,7 +45,7 @@
<StyleInclude Source="resm:Avalonia.Themes.Default.CalendarDayButton.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.CalendarDayButton.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.CalendarItem.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.CalendarItem.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Calendar.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.Calendar.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.DatePicker.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.CalendarDatePicker.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ButtonSpinner.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.ButtonSpinner.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.NumericUpDown.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.NumericUpDown.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.AutoCompleteBox.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.AutoCompleteBox.xaml?assembly=Avalonia.Themes.Default"/>

4
src/Avalonia.Themes.Default/DatePicker.xaml → src/Avalonia.Themes.Fluent/CalendarDatePicker.xaml

@ -8,7 +8,7 @@
<Styles xmlns="https://github.com/avaloniaui" <Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=netstandard"> xmlns:sys="clr-namespace:System;assembly=netstandard">
<Style Selector="DatePicker"> <Style Selector="CalendarDatePicker">
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/> <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
@ -119,7 +119,7 @@
</Setter> </Setter>
</Style> </Style>
<Style Selector="DatePicker:focus /template/ TextBox#PART_TextBox"> <Style Selector="CalendarDatePicker:focus /template/ TextBox#PART_TextBox">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style> </Style>

2
src/Avalonia.Themes.Fluent/FluentTheme.xaml

@ -44,7 +44,7 @@
<StyleInclude Source="resm:Avalonia.Themes.Fluent.CalendarDayButton.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.CalendarDayButton.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.CalendarItem.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.CalendarItem.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.Calendar.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.Calendar.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.DatePicker.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.CalendarDatePicker.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.ButtonSpinner.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.ButtonSpinner.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.NumericUpDown.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.NumericUpDown.xaml?assembly=Avalonia.Themes.Fluent"/>
<StyleInclude Source="resm:Avalonia.Themes.Fluent.AutoCompleteBox.xaml?assembly=Avalonia.Themes.Fluent"/> <StyleInclude Source="resm:Avalonia.Themes.Fluent.AutoCompleteBox.xaml?assembly=Avalonia.Themes.Fluent"/>

14
tests/Avalonia.Controls.UnitTests/DatePickerTests.cs → tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs

@ -15,7 +15,7 @@ using Xunit;
namespace Avalonia.Controls.UnitTests namespace Avalonia.Controls.UnitTests
{ {
public class DatePickerTests public class CalendarDatePickerTests
{ {
private static bool CompareDates(DateTime first, DateTime second) private static bool CompareDates(DateTime first, DateTime second)
{ {
@ -30,7 +30,7 @@ namespace Avalonia.Controls.UnitTests
using (UnitTestApplication.Start(Services)) using (UnitTestApplication.Start(Services))
{ {
bool handled = false; bool handled = false;
DatePicker datePicker = CreateControl(); CalendarDatePicker datePicker = CreateControl();
datePicker.SelectedDateChanged += (s,e) => datePicker.SelectedDateChanged += (s,e) =>
{ {
handled = true; handled = true;
@ -47,7 +47,7 @@ namespace Avalonia.Controls.UnitTests
{ {
using (UnitTestApplication.Start(Services)) using (UnitTestApplication.Start(Services))
{ {
DatePicker datePicker = CreateControl(); CalendarDatePicker datePicker = CreateControl();
datePicker.BlackoutDates.AddDatesInPast(); datePicker.BlackoutDates.AddDatesInPast();
DateTime goodValue = DateTime.Today.AddDays(1); DateTime goodValue = DateTime.Today.AddDays(1);
@ -65,7 +65,7 @@ namespace Avalonia.Controls.UnitTests
{ {
using (UnitTestApplication.Start(Services)) using (UnitTestApplication.Start(Services))
{ {
DatePicker datePicker = CreateControl(); CalendarDatePicker datePicker = CreateControl();
datePicker.SelectedDate = DateTime.Today.AddDays(5); datePicker.SelectedDate = DateTime.Today.AddDays(5);
Assert.ThrowsAny<ArgumentOutOfRangeException>( Assert.ThrowsAny<ArgumentOutOfRangeException>(
@ -76,10 +76,10 @@ namespace Avalonia.Controls.UnitTests
private static TestServices Services => TestServices.MockThreadingInterface.With( private static TestServices Services => TestServices.MockThreadingInterface.With(
standardCursorFactory: Mock.Of<IStandardCursorFactory>()); standardCursorFactory: Mock.Of<IStandardCursorFactory>());
private DatePicker CreateControl() private CalendarDatePicker CreateControl()
{ {
var datePicker = var datePicker =
new DatePicker new CalendarDatePicker
{ {
Template = CreateTemplate() Template = CreateTemplate()
}; };
@ -90,7 +90,7 @@ namespace Avalonia.Controls.UnitTests
private IControlTemplate CreateTemplate() private IControlTemplate CreateTemplate()
{ {
return new FuncControlTemplate<DatePicker>((control, scope) => return new FuncControlTemplate<CalendarDatePicker>((control, scope) =>
{ {
var textBox = var textBox =
new TextBox new TextBox
Loading…
Cancel
Save