Skip to content

Commit

Permalink
Add datetime check in NullConverters
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane ANDRE (E104915) committed Nov 7, 2024
1 parent d28f05d commit ac34bec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/MyNet.Wpf/Converters/NullToBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class NullToBooleanConverter(bool nullValue = true)
flag = arr.Length == 0;
}

if (value is DateTime date)
{
flag = date == DateTime.MinValue;
}

return flag ? _nullValue : !_nullValue;
}

Expand Down
5 changes: 5 additions & 0 deletions src/MyNet.Wpf/Converters/NullToVisibilityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class NullToVisibilityConverter(Visibility notNullVisibility = Visibility
flag = arr.Length == 0;
}

if (value is DateTime date)
{
flag = date == DateTime.MinValue;
}

return flag ? _nullVisibility : _notNullVisibility;
}

Expand Down
18 changes: 2 additions & 16 deletions src/MyNet.Wpf/Parameters/TextFieldAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,9 @@ private static void PasswordBoxOnPasswordChanged(object sender, RoutedEventArgs

#endregion

#region ClearControlCommand

public static readonly WpfCommand<UIElement> ClearControlCommand = new(x => Clear(x!));

public static bool GetClearControlParameter(DependencyObject obj)
=> (bool)obj.GetValue(ClearControlParameterProperty);

public static void SetClearControlParameter(DependencyObject obj, bool value)
=> obj.SetValue(ClearControlParameterProperty, value);

public static readonly DependencyProperty ClearControlParameterProperty =
DependencyProperty.RegisterAttached("ClearControlParameter", typeof(UIElement), typeof(TextFieldAssist), new PropertyMetadata(null));

#endregion

#region ClearTextCommand

public static readonly WpfCommand<UIElement> ClearControlCommand = new(x => Clear(x!));
public static readonly RoutedCommand ClearCommand = new();

public static bool GetHandlesClearCommand(DependencyObject obj)
Expand Down Expand Up @@ -280,7 +266,7 @@ private static void Clear(object source)
calendar.SetCurrentValue(System.Windows.Controls.Calendar.SelectedDateProperty, null);
break;
case Clock clock:
clock.SetCurrentValue(MaterialDesignThemes.Wpf.Clock.TimeProperty, null);
clock.SetCurrentValue(MaterialDesignThemes.Wpf.Clock.TimeProperty, DateTime.MinValue);
break;
}
}
Expand Down

0 comments on commit ac34bec

Please sign in to comment.