feat: improve range picker context initialization.
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
Name="{x:Static u:DateRangePicker.PART_Button}"
|
||||
Grid.Column="3"
|
||||
Padding="8,0"
|
||||
Content="{DynamicResource TimePickerIconGlyph}"
|
||||
Content="{DynamicResource CalendarDatePickerIconGlyph}"
|
||||
Focusable="False"
|
||||
Theme="{DynamicResource InnerIconButton}" />
|
||||
</Grid>
|
||||
@@ -87,6 +87,30 @@
|
||||
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
|
||||
ClipToBounds="True"
|
||||
CornerRadius="6">
|
||||
<DockPanel>
|
||||
<!--
|
||||
<StackPanel DockPanel.Dock="Bottom" IsVisible="{TemplateBinding NeedConfirmation}">
|
||||
<Button
|
||||
Margin="8"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{Binding $parent[u:TimeRangePicker].Confirm}"
|
||||
Content="{DynamicResource STRING_DATE_TIME_CONFIRM}" />
|
||||
</StackPanel>
|
||||
-->
|
||||
<ContentPresenter
|
||||
Name="PART_PopupHeader"
|
||||
Margin="8,8,8,0"
|
||||
Content="{TemplateBinding PopupInnerTopContent}"
|
||||
DockPanel.Dock="Top"
|
||||
IsVisible="{TemplateBinding PopupInnerTopContent,
|
||||
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||
<ContentPresenter
|
||||
Name="PART_PopupFooter"
|
||||
Margin="8,0,8,8"
|
||||
Content="{TemplateBinding PopupInnerBottomContent}"
|
||||
DockPanel.Dock="Bottom"
|
||||
IsVisible="{TemplateBinding PopupInnerBottomContent,
|
||||
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||
<Grid ColumnDefinitions="*, *">
|
||||
<u:CalendarView
|
||||
Name="{x:Static u:DateRangePicker.PART_StartCalendar}"
|
||||
@@ -105,6 +129,7 @@
|
||||
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
|
||||
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Panel>
|
||||
|
||||
@@ -13,4 +13,9 @@ public class CalendarContext(int? year = null, int? month = null, int? day = nul
|
||||
{
|
||||
return new CalendarContext(Year, Month, Day) { StartYear = StartYear, EndYear = EndYear };
|
||||
}
|
||||
|
||||
public static CalendarContext Today()
|
||||
{
|
||||
return new CalendarContext(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
}
|
||||
}
|
||||
@@ -217,26 +217,37 @@ public class DateRangePicker : DatePickerBase
|
||||
|
||||
if (_endCalendar is not null)
|
||||
{
|
||||
var date2 = SelectedEndDate ?? SelectedStartDate ?? DateTime.Today;
|
||||
_endCalendar.ContextCalendar = new CalendarContext(date2.Year, date2.Month, 1);
|
||||
var date2 = SelectedEndDate;
|
||||
if (date2 is null || (date2.Value.Year==SelectedStartDate?.Year && date2.Value.Month == SelectedStartDate?.Month))
|
||||
{
|
||||
date2 = SelectedStartDate ?? DateTime.Today;
|
||||
date2 = date2.Value.AddMonths(1);
|
||||
}
|
||||
_endCalendar.ContextCalendar = new CalendarContext(date2?.Year, date2?.Month, 1);
|
||||
_endCalendar.UpdateDayButtons();
|
||||
}
|
||||
}
|
||||
else if (sender == _endTextBox)
|
||||
{
|
||||
_start = false;
|
||||
if (_startCalendar is not null)
|
||||
{
|
||||
var date2 = SelectedStartDate ?? SelectedEndDate ?? DateTime.Today;
|
||||
_startCalendar.ContextCalendar = new CalendarContext(date2.Year, date2.Month, 1);
|
||||
_startCalendar.UpdateDayButtons();
|
||||
}
|
||||
if (_endCalendar is not null)
|
||||
{
|
||||
var date = SelectedEndDate ?? DateTime.Today;
|
||||
_endCalendar.ContextCalendar = new CalendarContext(date.Year, date.Month, 1);
|
||||
_endCalendar.UpdateDayButtons();
|
||||
}
|
||||
if (_startCalendar is not null)
|
||||
{
|
||||
var date2 = SelectedStartDate;
|
||||
if (date2 is null || (date2.Value.Year==SelectedEndDate?.Year && date2.Value.Month == SelectedEndDate?.Month))
|
||||
{
|
||||
date2 = SelectedStartDate ?? DateTime.Today;
|
||||
date2 = date2.Value.AddMonths(-1);
|
||||
}
|
||||
_startCalendar.ContextCalendar = new CalendarContext(date2?.Year, date2?.Month, 1);
|
||||
_startCalendar.UpdateDayButtons();
|
||||
}
|
||||
|
||||
}
|
||||
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user