feat: improve range picker context initialization.
This commit is contained in:
@@ -66,7 +66,7 @@
|
|||||||
Name="{x:Static u:DateRangePicker.PART_Button}"
|
Name="{x:Static u:DateRangePicker.PART_Button}"
|
||||||
Grid.Column="3"
|
Grid.Column="3"
|
||||||
Padding="8,0"
|
Padding="8,0"
|
||||||
Content="{DynamicResource TimePickerIconGlyph}"
|
Content="{DynamicResource CalendarDatePickerIconGlyph}"
|
||||||
Focusable="False"
|
Focusable="False"
|
||||||
Theme="{DynamicResource InnerIconButton}" />
|
Theme="{DynamicResource InnerIconButton}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -87,24 +87,49 @@
|
|||||||
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
|
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
|
||||||
ClipToBounds="True"
|
ClipToBounds="True"
|
||||||
CornerRadius="6">
|
CornerRadius="6">
|
||||||
<Grid ColumnDefinitions="*, *">
|
<DockPanel>
|
||||||
<u:CalendarView
|
<!--
|
||||||
Name="{x:Static u:DateRangePicker.PART_StartCalendar}"
|
<StackPanel DockPanel.Dock="Bottom" IsVisible="{TemplateBinding NeedConfirmation}">
|
||||||
Grid.Column="0"
|
<Button
|
||||||
Margin="8"
|
Margin="8"
|
||||||
BorderThickness="0"
|
HorizontalAlignment="Right"
|
||||||
CornerRadius="{Binding $parent[Border].CornerRadius}"
|
Command="{Binding $parent[u:TimeRangePicker].Confirm}"
|
||||||
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
|
Content="{DynamicResource STRING_DATE_TIME_CONFIRM}" />
|
||||||
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
|
</StackPanel>
|
||||||
<u:CalendarView
|
-->
|
||||||
Name="{x:Static u:DateRangePicker.PART_EndCalendar}"
|
<ContentPresenter
|
||||||
Grid.Column="1"
|
Name="PART_PopupHeader"
|
||||||
Margin="8"
|
Margin="8,8,8,0"
|
||||||
BorderThickness="0"
|
Content="{TemplateBinding PopupInnerTopContent}"
|
||||||
CornerRadius="{Binding $parent[Border].CornerRadius}"
|
DockPanel.Dock="Top"
|
||||||
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
|
IsVisible="{TemplateBinding PopupInnerTopContent,
|
||||||
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
|
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
</Grid>
|
<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}"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="8"
|
||||||
|
BorderThickness="0"
|
||||||
|
CornerRadius="{Binding $parent[Border].CornerRadius}"
|
||||||
|
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
|
||||||
|
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
|
||||||
|
<u:CalendarView
|
||||||
|
Name="{x:Static u:DateRangePicker.PART_EndCalendar}"
|
||||||
|
Grid.Column="1"
|
||||||
|
Margin="8"
|
||||||
|
BorderThickness="0"
|
||||||
|
CornerRadius="{Binding $parent[Border].CornerRadius}"
|
||||||
|
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
|
||||||
|
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
|
||||||
|
</Grid>
|
||||||
|
</DockPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Popup>
|
</Popup>
|
||||||
</Panel>
|
</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 };
|
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)
|
if (_endCalendar is not null)
|
||||||
{
|
{
|
||||||
var date2 = SelectedEndDate ?? SelectedStartDate ?? DateTime.Today;
|
var date2 = SelectedEndDate;
|
||||||
_endCalendar.ContextCalendar = new CalendarContext(date2.Year, date2.Month, 1);
|
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();
|
_endCalendar.UpdateDayButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sender == _endTextBox)
|
else if (sender == _endTextBox)
|
||||||
{
|
{
|
||||||
_start = false;
|
_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)
|
if (_endCalendar is not null)
|
||||||
{
|
{
|
||||||
var date = SelectedEndDate ?? DateTime.Today;
|
var date = SelectedEndDate ?? DateTime.Today;
|
||||||
_endCalendar.ContextCalendar = new CalendarContext(date.Year, date.Month, 1);
|
_endCalendar.ContextCalendar = new CalendarContext(date.Year, date.Month, 1);
|
||||||
_endCalendar.UpdateDayButtons();
|
_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);
|
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user