diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml index fc435998e..3a72593df 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml +++ b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml @@ -20,6 +20,7 @@ Content="Apply" CommandParameter="{TemplateBinding ApplyCommandParameter}" Command="{TemplateBinding ApplyCommand}" + CommandTarget="{TemplateBinding ApplyCommandTarget}" IsDefault="True" Focusable="False" Style="{StaticResource CommonButton}" diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml.cs b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml.cs index e2a937f90..f0435cebd 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterContentControl.xaml.cs @@ -24,6 +24,11 @@ namespace mbts.ui.spark { public object ApplyCommandParameter { get => GetValue(ApplyCommandParameterProperty); set => SetValue(ApplyCommandParameterProperty, value); } #endregion + #region ApplyCommandTarget + public static readonly DependencyProperty ApplyCommandTargetProperty = WPFHelper.create_dp(nameof(ApplyCommandTarget)); + public IInputElement ApplyCommandTarget { get => GetValue(ApplyCommandTargetProperty) as IInputElement; set => SetValue(ApplyCommandTargetProperty, value); } + #endregion + #region ClearCommand public static readonly DependencyProperty ClearCommandProperty = DependencyProperty.Register( nameof(ClearCommand), typeof(ICommand), typeof(FilterContentControl)); diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml index fe7935ec4..925c3958a 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml +++ b/src/client/spark/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml @@ -106,6 +106,7 @@ @@ -115,6 +116,9 @@ Begin="{Binding begin}" End="{Binding end}" > + + + diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/Views/TimeFilterControl.xaml.cs b/src/client/spark/view/Controls/DataGridEx/Filters/Views/TimeFilterControl.xaml.cs index 5fe4ecc5c..48e4fd1f2 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/Views/TimeFilterControl.xaml.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/Views/TimeFilterControl.xaml.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; +using System.Windows.Input; using System.Windows.Media; namespace mbts.ui.controls { @@ -14,6 +15,18 @@ namespace mbts.ui.controls { /// Interaction logic for TimeFilterControl.xaml /// public class TimeFilterControl : Control { + public static readonly ExecutedRoutedEventHandler CommitExecuted = (s, e) => { + if (s is TimeFilterControl tfc) { + tfc.get_template_child(_begin_dtp_name)?.flush_pending_changes(); + tfc.get_template_child(_end_dtp_name)?.flush_pending_changes(); + (e.Parameter as IDataGridColumnFilter)?.apply.TryExecuteIfCan(null); + e.Handled = true; + } + }; + const string + _begin_dtp_name = "PART_Begin_DateTimePicker", + _end_dtp_name = "PART_End_DateTimePicker"; + static TimeFilterControl() => DefaultStyleKeyProperty.OverrideMetadata(typeof(TimeFilterControl), new FrameworkPropertyMetadata(typeof(TimeFilterControl))); @@ -54,8 +67,8 @@ namespace mbts.ui.controls { readonly ChildProperty _begin_picker, _end_picker; public TimeFilterErrorAdorner(TimeFilterControl view) : base(view) { - _begin_picker = child_property("PART_Begin_DateTimePicker"); - _end_picker = child_property("PART_End_DateTimePicker"); + _begin_picker = child_property(_begin_dtp_name); + _end_picker = child_property(_end_dtp_name); } protected override void OnRender(DrawingContext drawing_context) { diff --git a/src/client/spark/view/Controls/Time/DateTimePicker.xaml.cs b/src/client/spark/view/Controls/Time/DateTimePicker.xaml.cs index 1a81c9372..77165f730 100644 --- a/src/client/spark/view/Controls/Time/DateTimePicker.xaml.cs +++ b/src/client/spark/view/Controls/Time/DateTimePicker.xaml.cs @@ -18,6 +18,11 @@ namespace mbts.ui.controls { public static readonly RoutedCommand TickTimeComponentCommand = new RoutedCommand(); DTPController _controller; + TextBox + _month_text, + _day_text, + _year_text, + _time_text; bool _suspend_notify_vm; static DateTimePicker() => @@ -34,18 +39,25 @@ namespace mbts.ui.controls { IList _hooks = new List(); + public void flush_pending_changes() { + _month_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource(); + _day_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource(); + _year_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource(); + _time_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource(); + } + public override void OnApplyTemplate() { var month = this.assert_template_child("PART_month_tick"); - var month_text = this.assert_template_child("PART_month_text"); + _month_text = this.assert_template_child("PART_month_text"); var day = this.assert_template_child("PART_day_tick"); - var day_text = this.assert_template_child("PART_day_text"); + _day_text = this.assert_template_child("PART_day_text"); var year = this.assert_template_child("PART_year_tick"); - var year_text = this.assert_template_child("PART_year_text"); + _year_text = this.assert_template_child("PART_year_text"); var time = this.assert_template_child("PART_time_tick"); - var time_text = this.assert_template_child("PART_time_text"); + _time_text = this.assert_template_child("PART_time_text"); if (_controller != null) _controller.PropertyChanged -= _vm_PropertyChanged; - _controller = new DTPController(time_text); + _controller = new DTPController(_time_text); _controller.result = TimeTuple; _controller.PropertyChanged += _vm_PropertyChanged; time.CommandBindings.Add(new CommandBinding(TickTimeComponentCommand, (s, e) => { @@ -58,9 +70,9 @@ namespace mbts.ui.controls { time.TickDownParameter = -1; time.TickUpAltParameter = 60; time.TickDownAltParameter = -60; - time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _controller, ValidatesOnExceptions = true }); - _hooks.Add(time_text.SubscribePreviewTextInput((s, e) => { - string preview = time_text.PeekText(e); + _time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _controller, ValidatesOnExceptions = true }); + _hooks.Add(_time_text.SubscribePreviewTextInput((s, e) => { + string preview = _time_text.PeekText(e); if (RegexFilters.Time.StandardTimeOptionalSeconds.IsMatch(preview)) { _controller.use_military_time = false; } else if (RegexFilters.Time.MilitaryTimeOptionalSeconds.IsMatch(preview)) { @@ -73,25 +85,25 @@ namespace mbts.ui.controls { month.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_month") { Source = _controller }); month.TickUpParameter = 1; month.TickDownParameter = -1; - month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _controller }); - _hooks.Add(month_text.SubscribePreviewTextInput((s, e) => - e.Handled = !RegexFilters.Time.MonthAbbrev.IsMatch(month_text.PeekText(e)) + _month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _controller }); + _hooks.Add(_month_text.SubscribePreviewTextInput((s, e) => + e.Handled = !RegexFilters.Time.MonthAbbrev.IsMatch(_month_text.PeekText(e)) )); day.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_day") { Source = _controller }); day.TickUpParameter = 1; day.TickDownParameter = -1; - day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _controller }); - _hooks.Add(day_text.SubscribePreviewTextInput((s, e) => - e.Handled = !RegexFilters.Time.DaysInMonth.IsMatch(day_text.PeekText(e)) + _day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _controller }); + _hooks.Add(_day_text.SubscribePreviewTextInput((s, e) => + e.Handled = !RegexFilters.Time.DaysInMonth.IsMatch(_day_text.PeekText(e)) )); year.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_year") { Source = _controller }); year.TickUpParameter = 1; year.TickDownParameter = -1; - year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _controller }); - _hooks.Add(year_text.SubscribePreviewTextInput((s, e) => - e.Handled = !RegexFilters.Time.Year.IsMatch(year_text.PeekText(e)) + _year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _controller }); + _hooks.Add(_year_text.SubscribePreviewTextInput((s, e) => + e.Handled = !RegexFilters.Time.Year.IsMatch(_year_text.PeekText(e)) )); }