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