Skip to content

Commit 09acf18

Browse files
committed
Ensure selected time always displays initial value. Alternative fix to PR #418
1 parent f23b85b commit 09acf18

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
</ListBox>
6161

6262
<CheckBox IsChecked="{Binding ElementName=UnderlineCheckbox, Path=IsSelected}">Underline?</CheckBox>
63+
64+
<materialDesign:TimePicker Margin="0 16 0 0" SelectedTime="{Binding SelectedTime}" HorizontalAlignment="Left" />
6365

6466
</StackPanel>
6567

MainDemo.Wpf/ProvingGround.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public partial class ProvingGround : UserControl
2828
public ProvingGround()
2929
{
3030
InitializeComponent();
31-
DataContext = new ProvingGroundViewModel();
31+
DataContext = new ProvingGroundViewModel
32+
{
33+
SelectedTime = new DateTime(2000, 1, 1, 3, 15, 0)
34+
};
3235
}
3336

3437
private void Button_Click(object sender, RoutedEventArgs e)

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
192192
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
193193
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
194-
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="1 0 0 0" />
195194
<Setter Property="Template">
196195
<Setter.Value>
197196
<ControlTemplate TargetType="{x:Type TextBox}">
@@ -561,6 +560,7 @@
561560
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
562561
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
563562
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
563+
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="1 0 0 0" />
564564
<Setter Property="Template" Value="{StaticResource MaterialDesignFloatingHintComboBoxTemplate}" />
565565
<Style.Triggers>
566566
<Trigger Property="IsKeyboardFocused" Value="true">

MaterialDesignThemes.Wpf/TimePicker.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class TimePicker : Control
2626
private Button _dropDownButton;
2727
private bool _disablePopupReopen;
2828
private DateTime? _lastValidTime;
29+
private bool _isManuallyMutatingText;
2930

3031
static TimePicker()
3132
{
@@ -51,7 +52,8 @@ public TimePicker()
5152
private static void TextPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
5253
{
5354
var timePicker = (TimePicker) dependencyObject;
54-
timePicker.SetSelectedTime();
55+
if (!timePicker._isManuallyMutatingText)
56+
timePicker.SetSelectedTime();
5557
if (timePicker._textBox != null)
5658
timePicker._textBox.Text = dependencyPropertyChangedEventArgs.NewValue as string;
5759
}
@@ -68,7 +70,9 @@ public string Text
6870
private static void SelectedTimePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
6971
{
7072
var timePicker = (TimePicker) dependencyObject;
71-
timePicker.SetCurrentValue(TextProperty, timePicker.DateTimeToString(timePicker.SelectedTime));
73+
timePicker._isManuallyMutatingText = true;
74+
timePicker.SetCurrentValue(TextProperty, timePicker.DateTimeToString(timePicker.SelectedTime));
75+
timePicker._isManuallyMutatingText = false;
7276
timePicker._lastValidTime = timePicker.SelectedTime;
7377
}
7478

0 commit comments

Comments
 (0)