@ -19,12 +19,16 @@ namespace Avalonia.Controls
[TemplatePart("PART_MinuteDownButton", typeof(RepeatButton))]
[TemplatePart("PART_MinuteSelector", typeof(DateTimePickerPanel), IsRequired = true)]
[TemplatePart("PART_MinuteUpButton", typeof(RepeatButton))]
[TemplatePart("PART_SecondDownButton", typeof(RepeatButton))]
[TemplatePart("PART_SecondHost", typeof(Panel), IsRequired = true)]
[TemplatePart("PART_SecondSelector", typeof(DateTimePickerPanel), IsRequired = true)]
[TemplatePart("PART_SecondUpButton", typeof(RepeatButton))]
[TemplatePart("PART_PeriodDownButton", typeof(RepeatButton))]
[TemplatePart("PART_PeriodHost", typeof(Panel), IsRequired = true)]
[TemplatePart("PART_PeriodSelector", typeof(DateTimePickerPanel), IsRequired = true)]
[TemplatePart("PART_PeriodUpButton", typeof(RepeatButton))]
[TemplatePart("PART_PickerContainer", typeof(Grid), IsRequired = true)]
[TemplatePart("PART_Secon dSpacer", typeof(Rectangle), IsRequired = true)]
[TemplatePart("PART_Thir dSpacer", typeof(Rectangle), IsRequired = true)]
public class TimePickerPresenter : PickerPresenterBase
{
/// <summary>
@ -32,12 +36,24 @@ namespace Avalonia.Controls
/// </summary>
public static readonly StyledProperty < int > MinuteIncrementProperty =
TimePicker . MinuteIncrementProperty . AddOwner < TimePickerPresenter > ( ) ;
/// <summary>
/// Defines the <see cref="SecondIncrement"/> property
/// </summary>
public static readonly StyledProperty < int > SecondIncrementProperty =
TimePicker . SecondIncrementProperty . AddOwner < TimePickerPresenter > ( ) ;
/// <summary>
/// Defines the <see cref="ClockIdentifier"/> property
/// </summary>
public static readonly StyledProperty < string > ClockIdentifierProperty =
TimePicker . ClockIdentifierProperty . AddOwner < TimePickerPresenter > ( ) ;
/// <summary>
/// Defines the <see cref="UseSeconds"/> property
/// </summary>
public static readonly StyledProperty < bool > UseSecondsProperty =
TimePicker . UseSecondsProperty . AddOwner < TimePickerPresenter > ( ) ;
/// <summary>
/// Defines the <see cref="Time"/> property
@ -60,15 +76,20 @@ namespace Avalonia.Controls
private Button ? _ acceptButton ;
private Button ? _d ismissButton ;
private Rectangle ? _ spacer2 ;
private Rectangle ? _ spacer3 ;
private Panel ? _ secondHost ;
private Panel ? _ periodHost ;
private DateTimePickerPanel ? _ hourSelector ;
private DateTimePickerPanel ? _ minuteSelector ;
private DateTimePickerPanel ? _ secondSelector ;
private DateTimePickerPanel ? _ periodSelector ;
private Button ? _ hourUpButton ;
private Button ? _ minuteUpButton ;
private Button ? _ secondUpButton ;
private Button ? _ periodUpButton ;
private Button ? _ hourDownButton ;
private Button ? _ minuteDownButton ;
private Button ? _ secondDownButton ;
private Button ? _ periodDownButton ;
/// <summary>
@ -79,6 +100,15 @@ namespace Avalonia.Controls
get = > GetValue ( MinuteIncrementProperty ) ;
set = > SetValue ( MinuteIncrementProperty , value ) ;
}
/// <summary>
/// Gets or sets the second increment in the selector
/// </summary>
public int SecondIncrement
{
get = > GetValue ( SecondIncrementProperty ) ;
set = > SetValue ( SecondIncrementProperty , value ) ;
}
/// <summary>
/// Gets or sets the current clock identifier, either 12HourClock or 24HourClock
@ -88,6 +118,15 @@ namespace Avalonia.Controls
get = > GetValue ( ClockIdentifierProperty ) ;
set = > SetValue ( ClockIdentifierProperty , value ) ;
}
/// <summary>
/// Gets or sets the current clock identifier, either 12HourClock or 24HourClock
/// </summary>
public bool UseSeconds
{
get = > GetValue ( UseSecondsProperty ) ;
set = > SetValue ( UseSecondsProperty , value ) ;
}
/// <summary>
/// Gets or sets the current time
@ -104,12 +143,15 @@ namespace Avalonia.Controls
_ pickerContainer = e . NameScope . Get < Grid > ( "PART_PickerContainer" ) ;
_ periodHost = e . NameScope . Get < Panel > ( "PART_PeriodHost" ) ;
_ secondHost = e . NameScope . Get < Panel > ( "PART_SecondHost" ) ;
_ hourSelector = e . NameScope . Get < DateTimePickerPanel > ( "PART_HourSelector" ) ;
_ minuteSelector = e . NameScope . Get < DateTimePickerPanel > ( "PART_MinuteSelector" ) ;
_ secondSelector = e . NameScope . Get < DateTimePickerPanel > ( "PART_SecondSelector" ) ;
_ periodSelector = e . NameScope . Get < DateTimePickerPanel > ( "PART_PeriodSelector" ) ;
_ spacer2 = e . NameScope . Get < Rectangle > ( "PART_SecondSpacer" ) ;
_ spacer3 = e . NameScope . Get < Rectangle > ( "PART_ThirdSpacer" ) ;
_ acceptButton = e . NameScope . Get < Button > ( "PART_AcceptButton" ) ;
_ acceptButton . Click + = OnAcceptButtonClicked ;
@ -127,6 +169,13 @@ namespace Avalonia.Controls
_ minuteDownButton = e . NameScope . Find < RepeatButton > ( "PART_MinuteDownButton" ) ;
if ( _ minuteDownButton ! = null )
_ minuteDownButton . Click + = OnSelectorButtonClick ;
_ secondUpButton = e . NameScope . Find < RepeatButton > ( "PART_SecondUpButton" ) ;
if ( _ secondUpButton ! = null )
_ secondUpButton . Click + = OnSelectorButtonClick ;
_ secondDownButton = e . NameScope . Find < RepeatButton > ( "PART_SecondDownButton" ) ;
if ( _ secondDownButton ! = null )
_ secondDownButton . Click + = OnSelectorButtonClick ;
_ periodUpButton = e . NameScope . Find < RepeatButton > ( "PART_PeriodUpButton" ) ;
if ( _ periodUpButton ! = null )
@ -146,7 +195,11 @@ namespace Avalonia.Controls
{
base . OnPropertyChanged ( change ) ;
if ( change . Property = = MinuteIncrementProperty | | change . Property = = ClockIdentifierProperty | | change . Property = = TimeProperty )
if ( change . Property = = MinuteIncrementProperty | |
change . Property = = SecondIncrementProperty | |
change . Property = = ClockIdentifierProperty | |
change . Property = = UseSecondsProperty | |
change . Property = = TimeProperty )
{
InitPicker ( ) ;
}
@ -180,6 +233,7 @@ namespace Avalonia.Controls
{
var hr = _ hourSelector ! . SelectedValue ;
var min = _ minuteSelector ! . SelectedValue ;
var sec = _ secondSelector ! . SelectedValue ;
var per = _ periodSelector ! . SelectedValue ;
if ( ClockIdentifier = = "12HourClock" )
@ -187,7 +241,7 @@ namespace Avalonia.Controls
hr = per = = 1 ? ( hr = = 1 2 ) ? 1 2 : hr + 1 2 : per = = 0 & & hr = = 1 2 ? 0 : hr ;
}
SetCurrentValue ( TimeProperty , new TimeSpan ( hr , min , 0 ) ) ;
SetCurrentValue ( TimeProperty , new TimeSpan ( hr , min , sec ) ) ;
base . OnConfirmed ( ) ;
}
@ -210,6 +264,12 @@ namespace Avalonia.Controls
_ minuteSelector . Increment = MinuteIncrement ;
_ minuteSelector . SelectedValue = Time . Minutes ;
_ minuteSelector . ItemFormat = "mm" ;
_ secondSelector ! . MaximumValue = 5 9 ;
_ secondSelector . MinimumValue = 0 ;
_ secondSelector . Increment = SecondIncrement ;
_ secondSelector . SelectedValue = Time . Seconds ;
_ secondSelector . ItemFormat = "ss" ;
_ periodSelector ! . MaximumValue = 1 ;
_ periodSelector . MinimumValue = 0 ;
@ -223,14 +283,24 @@ namespace Avalonia.Controls
{
bool use24HourClock = ClockIdentifier = = "24HourClock" ;
var columnsD = use24HourClock ? "*, Auto, *" : "*, Auto, *, Auto, *" ;
var columnsD = "*, Auto, *" ;
if ( UseSeconds ) columnsD + = ", Auto *" ;
if ( ! use24HourClock ) columnsD + = ", Auto *" ;
_ pickerContainer ! . ColumnDefinitions = new ColumnDefinitions ( columnsD ) ;
_ spacer2 ! . IsVisible = ! use24HourClock ;
_ perio dHost! . IsVisible = ! use24HourClock ;
_ spacer2 ! . IsVisible = UseSeconds ;
_ secon dHost! . IsVisible = UseSeconds ;
Grid . SetColumn ( _ spacer2 , use24HourClock ? 0 : 3 ) ;
Grid . SetColumn ( _ periodHost , use24HourClock ? 0 : 4 ) ;
_ spacer3 ! . IsVisible = ! use24HourClock ;
_ periodHost ! . IsVisible = ! use24HourClock ;
var amPmColumn = ( UseSeconds ) ? 6 : 4 ;
Grid . SetColumn ( _ spacer2 , UseSeconds ? 3 : 0 ) ;
Grid . SetColumn ( _ secondHost , UseSeconds ? 4 : 0 ) ;
Grid . SetColumn ( _ spacer3 , use24HourClock ? 0 : amPmColumn - 1 ) ;
Grid . SetColumn ( _ periodHost , use24HourClock ? 0 : amPmColumn ) ;
}
private void OnDismissButtonClicked ( object? sender , RoutedEventArgs e )
@ -253,6 +323,10 @@ namespace Avalonia.Controls
_ minuteSelector ! . ScrollUp ( ) ;
else if ( sender = = _ minuteDownButton )
_ minuteSelector ! . ScrollDown ( ) ;
else if ( sender = = _ secondUpButton )
_ secondSelector ! . ScrollUp ( ) ;
else if ( sender = = _ secondDownButton )
_ secondSelector ! . ScrollDown ( ) ;
else if ( sender = = _ periodUpButton )
_ periodSelector ! . ScrollUp ( ) ;
else if ( sender = = _ periodDownButton )