Skip to content

Commit

Permalink
fix: close #1149
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Oct 27, 2022
1 parent 4654335 commit bf12723
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,72 @@
<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}">
<hc:TimePicker.Clock>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,6 @@ public override void OnApplyTemplate()
_popup.Closed += PopupClosed;
_popup.Child = _calendarWithClock;

if (IsDropDownOpen)
{
_popup.IsOpen = true;
}

_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;

Expand Down
40 changes: 29 additions & 11 deletions src/Shared/HandyControl_Shared/Controls/Input/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static TimePicker()

public TimePicker()
{
Clock = new Clock();
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
{
SetCurrentValue(SelectedTimeProperty, null);
Expand Down Expand Up @@ -142,13 +141,12 @@ public bool IsDropDownOpen
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)
{
Expand Down Expand Up @@ -351,13 +349,15 @@ private static void OnClockChanged(DependencyObject d, DependencyPropertyChanged
{
oldClock.SelectedTimeChanged -= ctl.Clock_SelectedTimeChanged;
oldClock.Confirmed -= ctl.Clock_Confirmed;
ctl.SetPopupChild(null);
}

if (e.NewValue is ClockBase newClock)
{
newClock.ShowConfirmButton = true;
newClock.SelectedTimeChanged += ctl.Clock_SelectedTimeChanged;
newClock.Confirmed += ctl.Clock_Confirmed;
ctl.SetPopupChild(newClock);
}
}

Expand Down Expand Up @@ -454,11 +454,6 @@ public override void OnApplyTemplate()
_popup.Closed += PopupClosed;
_popup.Child = Clock;

if (IsDropDownOpen)
{
_popup.IsOpen = true;
}

_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;

Expand Down Expand Up @@ -496,6 +491,8 @@ public override void OnApplyTemplate()
}
}

EnsureClock();

if (selectedTime is null)
{
_originalSelectedTime ??= DateTime.Now;
Expand All @@ -517,12 +514,14 @@ protected virtual void OnClockClosed(RoutedEventArgs e)
{
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
Expand Down Expand Up @@ -792,5 +791,24 @@ private static void OnGotFocus(object sender, RoutedEventArgs e)
}
}

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ protected void ButtonConfirm_OnClick(object sender, RoutedEventArgs e)
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()
{
}
}
41 changes: 24 additions & 17 deletions src/Shared/HandyControl_Shared/Controls/Time/Clock/ListClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ListClock : ClockBase

#endregion Data

public override void OnClockOpened() => ScrollIntoView();

public override void OnApplyTemplate()
{
AppliedTemplate = false;
Expand Down Expand Up @@ -94,6 +96,27 @@ public override void OnApplyTemplate()
}
}

/// <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();
Expand Down Expand Up @@ -124,26 +147,10 @@ private void Update()
}
}

/// <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;
}
}
6 changes: 3 additions & 3 deletions src/Shared/HandyControl_Shared/Themes/Styles/Clock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/HandyControl_Shared/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit bf12723

Please sign in to comment.