Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<converters:MathConverter Operation="Divide" x:Key="DivisionMathConverter" />

<Style x:Key="MaterialDesignTimePicker" TargetType="{x:Type wpf:TimePicker}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0 0 0 1"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0 0 0 1"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="wpf:HintAssist.Hint" Value="Select time" />
<Setter Property="ClockStyle" Value="{DynamicResource MaterialDesignClock}" />
Expand Down Expand Up @@ -100,7 +100,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox BorderThickness="0" x:Name="PART_TextBox"
<wpf:TimePickerTextBox BorderThickness="0" x:Name="PART_TextBox"
wpf:TextFieldAssist.TextBoxViewMargin=".5 0 0 0"
Margin="0"
Template="{StaticResource TextBoxTemplate}"
Expand Down
21 changes: 10 additions & 11 deletions MaterialDesignThemes.Wpf/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MaterialDesignThemes.Wpf
{
[TemplatePart(Name = ButtonPartName, Type = typeof(Button))]
[TemplatePart(Name = PopupPartName, Type = typeof(Popup))]
[TemplatePart(Name = TextBoxPartName, Type = typeof(TextBox))]
[TemplatePart(Name = TextBoxPartName, Type = typeof(TimePickerTextBox))]
public class TimePicker : Control
{
public const string ButtonPartName = "PART_Button";
Expand All @@ -36,10 +36,12 @@ static TimePicker()

public TimePicker()
{
_clock = new Clock {
_clock = new Clock
{
DisplayAutomation = ClockDisplayAutomation.ToMinutesOnly
};
_clockHostContentControl = new ContentControl {
_clockHostContentControl = new ContentControl
{
Content = _clock
};
InitializeClock();
Expand Down Expand Up @@ -172,7 +174,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyProper
//TODO set time
//dp._originalSelectedDate = dp.SelectedDate;

timePicker.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
timePicker.Dispatcher?.BeginInvoke(DispatcherPriority.Input, new Action(() =>
{
timePicker._clock.Focus();
}));
Expand Down Expand Up @@ -438,14 +440,13 @@ private string DateTimeToString(DateTime datetime, DatePickerFormat format)

private void PopupOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
var popup = sender as Popup;
if (popup == null || popup.StaysOpen) return;
if (!(sender is Popup popup) || popup.StaysOpen) return;

if (_dropDownButton?.InputHitTest(mouseButtonEventArgs.GetPosition(_dropDownButton)) != null)
{
// This popup is being closed by a mouse press on the drop down button
// The following mouse release will cause the closed popup to immediately reopen.
// Raise a flag to block reopeneing the popup
// Raise a flag to block re-opening the popup
_disablePopupReopen = true;
}
}
Expand Down Expand Up @@ -495,10 +496,8 @@ private void InitializeClock()

private void ClockChoiceMadeHandler(object sender, ClockChoiceMadeEventArgs clockChoiceMadeEventArgs)
{
if (
(WithSeconds && (clockChoiceMadeEventArgs.Mode == ClockDisplayMode.Seconds)) ||
(!WithSeconds && (clockChoiceMadeEventArgs.Mode == ClockDisplayMode.Minutes))
)
if (WithSeconds && clockChoiceMadeEventArgs.Mode == ClockDisplayMode.Seconds ||
!WithSeconds && clockChoiceMadeEventArgs.Mode == ClockDisplayMode.Minutes)
{
TogglePopup();
if (SelectedTime == null)
Expand Down
13 changes: 13 additions & 0 deletions MaterialDesignThemes.Wpf/TimePickerTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Windows;
using System.Windows.Controls;

namespace MaterialDesignThemes.Wpf
{
public class TimePickerTextBox : TextBox
{
static TimePickerTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TimePickerTextBox), new FrameworkPropertyMetadata(typeof(TimePickerTextBox)));
}
}
}