This commit is contained in:
NaBian committed 2022-10-27 22:58:45 +08:00
1 parent 465433560f
commit bf1272399d
8 files changed
+125 -53

No files matched your search

@@ -12718,9 +12718,9 @@
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox hc:BorderElement.CornerRadius="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0" />
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}" />
<Border VerticalAlignment="Bottom" Visibility="{Binding Visibility,ElementName=PART_ButtonConfirm}" Height="1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="{DynamicResource BorderBrush}" />
<Button Margin="0,10" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Background="Transparent" Style="{StaticResource ButtonCustom}" />
</Grid>
@@ -33,14 +33,38 @@
<hc:TimePicker Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource TimePickerPlus}" hc:InfoElement.Necessary="True" Margin="0,16,0,0"/>
</StackPanel>
<StackPanel>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePicker.Small}"/>
<hc:TimePicker Margin="0,16,0,0" IsEnabled="False" Style="{StaticResource TimePicker.Small}"/>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePicker.Small}">
<hc:TimePicker.Clock>
<hc:ListClock/>
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker Margin="0,16,0,0" IsEnabled="False" Style="{StaticResource TimePicker.Small}">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0"/>
<hc:TimePicker hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr2}}" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr2}}" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker ShowClearButton="True" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Margin="0,32,0,0"/>
<hc:TimePicker Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<hc:TimePicker ShowClearButton="True" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Margin="0,32,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource TimePickerExtend.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
</StackPanel>
<StackPanel Margin="32,0,0,0">
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus.Small}">
@@ -48,13 +72,33 @@
<hc:ListClock/>
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker ShowClearButton="True" Margin="0,16,0,0" Style="{StaticResource TimePickerPlus.Small}"/>
<hc:TimePicker ShowClearButton="True" Margin="0,16,0,0" Style="{StaticResource TimePickerPlus.Small}">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0"/>
<hc:TimePicker hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr2}}" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<hc:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr2}}" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker ShowClearButton="True" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Margin="0,32,0,0"/>
<hc:TimePicker Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<hc:TimePicker ShowClearButton="True" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Margin="0,32,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
<hc:TimePicker Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource TimePickerPlus.Small}" hc:InfoElement.Necessary="True" Margin="0,16,0,0">
<hc:TimePicker.Clock>
<hc:ListClock />
</hc:TimePicker.Clock>
</hc:TimePicker>
</StackPanel>
</hc:UniformSpacingPanel>
</hc:ScrollViewer>
@@ -357,11 +357,6 @@ public class DateTimePicker : Control, IDataInput
_popup.Closed += PopupClosed;
_popup.Child = _calendarWithClock;
if (IsDropDownOpen)
{
_popup.IsOpen = true;
}
_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;
@@ -79,7 +79,6 @@ public class TimePicker : Control, IDataInput
public TimePicker()
{
Clock = new Clock();
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
{
SetCurrentValue(SelectedTimeProperty, null);
@@ -142,13 +141,12 @@ public class TimePicker : Control, IDataInput
typeof(TimePicker),
new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsDropDownOpenChanged, OnCoerceIsDropDownOpen));
private static object OnCoerceIsDropDownOpen(DependencyObject d, object baseValue) =>
d is TimePicker
{
IsEnabled: false
}
private static object OnCoerceIsDropDownOpen(DependencyObject d, object baseValue)
{
return d is TimePicker { IsEnabled: false }
? false
: baseValue;
}
private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
@@ -351,6 +349,7 @@ public class TimePicker : Control, IDataInput
{
oldClock.SelectedTimeChanged -= ctl.Clock_SelectedTimeChanged;
oldClock.Confirmed -= ctl.Clock_Confirmed;
ctl.SetPopupChild(null);
}
if (e.NewValue is ClockBase newClock)
@@ -358,6 +357,7 @@ public class TimePicker : Control, IDataInput
newClock.ShowConfirmButton = true;
newClock.SelectedTimeChanged += ctl.Clock_SelectedTimeChanged;
newClock.Confirmed += ctl.Clock_Confirmed;
ctl.SetPopupChild(newClock);
}
}
@@ -454,11 +454,6 @@ public class TimePicker : Control, IDataInput
_popup.Closed += PopupClosed;
_popup.Child = Clock;
if (IsDropDownOpen)
{
_popup.IsOpen = true;
}
_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;
@@ -496,6 +491,8 @@ public class TimePicker : Control, IDataInput
}
}
EnsureClock();
if (selectedTime is null)
{
_originalSelectedTime ??= DateTime.Now;
@@ -517,12 +514,14 @@ public class TimePicker : Control, IDataInput
{
var handler = ClockClosed;
handler?.Invoke(this, e);
Clock?.OnClockClosed();
}
protected virtual void OnClockOpened(RoutedEventArgs e)
{
var handler = ClockOpened;
handler?.Invoke(this, e);
Clock?.OnClockOpened();
}
#endregion Protected Methods
@@ -792,5 +791,24 @@ public class TimePicker : Control, IDataInput
}
}
private void EnsureClock()
{
if (Clock is not null)
{
return;
}
SetCurrentValue(ClockProperty, new Clock());
SetPopupChild(Clock);
}
private void SetPopupChild(UIElement element)
{
if (_popup is not null)
{
_popup.Child = Clock;
}
}
#endregion Private Methods
}
@@ -102,4 +102,12 @@ public abstract class ClockBase : Control
internal abstract void Update(DateTime time);
protected void Clock_SelectedTimeChanged(object sender, FunctionEventArgs<DateTime?> e) => SelectedTime = e.Info;
public virtual void OnClockClosed()
{
}
public virtual void OnClockOpened()
{
}
}
@@ -29,6 +29,8 @@ public class ListClock : ClockBase
#endregion Data
public override void OnClockOpened() => ScrollIntoView();
public override void OnApplyTemplate()
{
AppliedTemplate = false;
@@ -94,6 +96,27 @@ public class ListClock : ClockBase
}
}
/// <summary>
/// 更新
/// </summary>
/// <param name="time"></param>
internal override void Update(DateTime time)
{
if (!AppliedTemplate) return;
var h = time.Hour;
var m = time.Minute;
var s = time.Second;
_hourList.SelectedIndex = h;
_minuteList.SelectedIndex = m;
_secondList.SelectedIndex = s;
ScrollIntoView();
DisplayTime = time;
}
private void HourList_SelectionChanged(object sender, SelectionChangedEventArgs e) => Update();
private void MinuteList_SelectionChanged(object sender, SelectionChangedEventArgs e) => Update();
@@ -124,26 +147,10 @@ public class ListClock : ClockBase
}
}
/// <summary>
/// 更新
/// </summary>
/// <param name="time"></param>
internal override void Update(DateTime time)
private void ScrollIntoView()
{
if (!AppliedTemplate) return;
var h = time.Hour;
var m = time.Minute;
var s = time.Second;
_hourList.SelectedIndex = h;
_minuteList.SelectedIndex = m;
_secondList.SelectedIndex = s;
_hourList.ScrollIntoView(_hourList.SelectedItem);
_minuteList.ScrollIntoView(_minuteList.SelectedItem);
_secondList.ScrollIntoView(_secondList.SelectedItem);
DisplayTime = time;
}
}
@@ -157,9 +157,9 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox hc:BorderElement.CornerRadius="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}"/>
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0"/>
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}"/>
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}"/>
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0"/>
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}"/>
<Border VerticalAlignment="Bottom" Visibility="{Binding Visibility,ElementName=PART_ButtonConfirm}" Height="1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="{DynamicResource BorderBrush}"/>
<Button Margin="0,10" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Background="Transparent" Style="{StaticResource ButtonCustom}"/>
</Grid>
@@ -12850,9 +12850,9 @@
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox hc:BorderElement.CornerRadius="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0" />
<ListBox hc:BorderElement.CornerRadius="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0" />
<ListBox hc:BorderElement.CornerRadius="0" Padding="0" Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}" />
<Border VerticalAlignment="Bottom" Visibility="{Binding Visibility,ElementName=PART_ButtonConfirm}" Height="1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="{DynamicResource BorderBrush}" />
<Button Margin="0,10" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Background="Transparent" Style="{StaticResource ButtonCustom}" />
</Grid>