fix: fix panel format change handling.
This commit is contained in:
@@ -11,21 +11,36 @@
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<ToggleSwitch Name="needConfirm" Content="Need Confirm" />
|
||||
<TextBlock Text="{Binding #picker.SelectedTime}" />
|
||||
<TextBox
|
||||
Name="displayFormat"
|
||||
Width="300"
|
||||
InnerLeftContent="Display Format"
|
||||
Text="HH 时 mm 分 ss 秒" />
|
||||
<TextBox
|
||||
Name="panelFormat"
|
||||
Width="300"
|
||||
InnerLeftContent="Panel Format"
|
||||
Text="tt HH mm ss" />
|
||||
<u:TimePicker
|
||||
Name="picker"
|
||||
Width="200"
|
||||
HorizontalAlignment="Left"
|
||||
DisplayFormat="{Binding #displayFormat.Text}"
|
||||
NeedConfirmation="{Binding #needConfirm.IsChecked}"
|
||||
PanelFormat="hh mm tt" />
|
||||
PanelFormat="{Binding #panelFormat.Text}" />
|
||||
|
||||
<u:TimePicker
|
||||
Width="300"
|
||||
Classes="ClearButton"
|
||||
DisplayFormat="HH 时 mm 分 ss 秒"
|
||||
PanelFormat="tt HH mm ss"
|
||||
HorizontalAlignment="Left"
|
||||
NeedConfirmation="True"
|
||||
Classes="ClearButton"
|
||||
DisplayFormat="{Binding #displayFormat.Text}"
|
||||
InnerLeftContent="时刻"
|
||||
InnerRightContent="截止" />
|
||||
<u:TimeRangePicker Width="300"></u:TimeRangePicker>
|
||||
InnerRightContent="截止"
|
||||
NeedConfirmation="True"
|
||||
PanelFormat="{Binding #panelFormat.Text}" />
|
||||
<u:TimeRangePicker
|
||||
Width="300"
|
||||
DisplayFormat="{Binding #displayFormat.Text}"
|
||||
PanelFormat="{Binding #panelFormat.Text}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -141,31 +141,38 @@ public class TimePickerPresenter : TemplatedControl
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (part.Length < 1) continue;
|
||||
if ((part.Contains('h') || part.Contains('H')) && !panels.Contains(_hourScrollPanel))
|
||||
try
|
||||
{
|
||||
panels.Add(_hourScrollPanel);
|
||||
_use12Clock = part.Contains('h');
|
||||
_hourSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part.ToLower());
|
||||
if (_hourSelector is not null)
|
||||
if ((part.Contains('h') || part.Contains('H')) && !panels.Contains(_hourScrollPanel))
|
||||
{
|
||||
_hourSelector.MaximumValue = _use12Clock ? 12 : 23;
|
||||
_hourSelector.MinimumValue = _use12Clock ? 1: 0;
|
||||
panels.Add(_hourScrollPanel);
|
||||
_use12Clock = part.Contains('h');
|
||||
_hourSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part.ToLower());
|
||||
if (_hourSelector is not null)
|
||||
{
|
||||
_hourSelector.MaximumValue = _use12Clock ? 12 : 23;
|
||||
_hourSelector.MinimumValue = _use12Clock ? 1 : 0;
|
||||
}
|
||||
}
|
||||
else if (part[0] == 'm' && !panels.Contains(_minuteSelector))
|
||||
{
|
||||
panels.Add(_minuteScrollPanel);
|
||||
_minuteSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part);
|
||||
}
|
||||
else if (part[0] == 's' && !panels.Contains(_secondScrollPanel))
|
||||
{
|
||||
panels.Add(_secondScrollPanel);
|
||||
_secondSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part.Replace('s', 'm'));
|
||||
}
|
||||
else if (part[0] == 't' && !panels.Contains(_ampmScrollPanel))
|
||||
{
|
||||
panels.Add(_ampmScrollPanel);
|
||||
_ampmSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part);
|
||||
}
|
||||
}
|
||||
else if (part[0] == 'm' && !panels.Contains(_minuteSelector))
|
||||
catch
|
||||
{
|
||||
panels.Add(_minuteScrollPanel);
|
||||
_minuteSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part);
|
||||
}
|
||||
else if (part[0] == 's' && !panels.Contains(_secondScrollPanel))
|
||||
{
|
||||
panels.Add(_secondScrollPanel);
|
||||
_secondSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part.Replace('s', 'm'));
|
||||
}
|
||||
else if (part[0] == 't' && !panels.Contains(_ampmScrollPanel))
|
||||
{
|
||||
panels.Add(_ampmScrollPanel);
|
||||
_ampmSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user