Skip to content

Commit

Permalink
Fix Some Bugs #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Dec 17, 2024
1 parent a255674 commit 31bf00b
Show file tree
Hide file tree
Showing 4 changed files with 6,141 additions and 9,688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,31 @@ public object Description
}

public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register(nameof(Description), typeof(object), typeof(DateTimePicker), new PropertyMetadata(default(object)));
DependencyProperty.Register(nameof(Description), typeof(object), typeof(DateTimePicker), new PropertyMetadata(default(object), OnDescriptionChanged));
private static void OnDescriptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (DateTimePicker)d;
if (ctl != null)
{
ctl.UpdateDescriptionVisibility();
}
}
public object Header
{
get { return (object)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}

public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register(nameof(Header), typeof(object), typeof(DateTimePicker), new PropertyMetadata(default(object)));
DependencyProperty.Register(nameof(Header), typeof(object), typeof(DateTimePicker), new PropertyMetadata(default(object), OnHeaderChanged));
private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (DateTimePicker)d;
if (ctl != null)
{
ctl.UpdateHeaderVisibility();
}
}
public DataTemplate HeaderTemplate
{
get { return (DataTemplate)GetValue(HeaderTemplateProperty); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@ namespace DevWinUI;
[TemplatePart(Name = nameof(PART_CalendarWithClockView), Type = typeof(CalendarWithClock))]
public partial class DateTimePicker : DateTimeBase
{
private readonly string HeaderContentPresenter = "HeaderContentPresenter";
private readonly string DescriptionPresenter = "DescriptionPresenter";
private readonly string PART_Root = "PART_Root";
private readonly string PART_ConfirmButton = "PART_ConfirmButton";
private readonly string PART_CalendarWithClockView = "PART_CalendarWithClockView";
private ContentPresenter headerContentPresenter;
private ContentPresenter descriptionContentPresenter;
private Grid rootGrid;
private Button confirmButton;
private CalendarWithClock calendarWithClock;

protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

headerContentPresenter = GetTemplateChild(nameof(HeaderContentPresenter)) as ContentPresenter;
descriptionContentPresenter = GetTemplateChild(nameof(DescriptionPresenter)) as ContentPresenter;

UpdateHeaderVisibility();
UpdateDescriptionVisibility();

rootGrid = GetTemplateChild(nameof(PART_Root)) as Grid;
confirmButton = GetTemplateChild(nameof(PART_ConfirmButton)) as Button;
calendarWithClock = GetTemplateChild(nameof(PART_CalendarWithClockView)) as CalendarWithClock;
Expand Down Expand Up @@ -100,4 +111,24 @@ private void UpdatePlaceholder()
{
PlaceholderText = $"{calendarWithClock.SelectedDateTime}";
}

private void UpdateHeaderVisibility()
{
if (headerContentPresenter != null)
{
headerContentPresenter.Visibility = Header == null
? Visibility.Collapsed
: Visibility.Visible;
}
}

private void UpdateDescriptionVisibility()
{
if (descriptionContentPresenter != null)
{
descriptionContentPresenter.Visibility = Description == null
? Visibility.Collapsed
: Visibility.Visible;
}
}
}
Loading

0 comments on commit 31bf00b

Please sign in to comment.