|
| 1 | +using System.Collections.Specialized; |
1 | 2 | using System.Windows.Input;
|
2 | 3 | using XCalendar.Core.Enums;
|
3 | 4 | using XCalendar.Core.Interfaces;
|
@@ -150,6 +151,11 @@ public StackOrientation EventsOrientation
|
150 | 151 | get { return (StackOrientation)GetValue(EventsOrientationProperty); }
|
151 | 152 | set { SetValue(EventsOrientationProperty, value); }
|
152 | 153 | }
|
| 154 | + public bool AutoEventsViewVisibility |
| 155 | + { |
| 156 | + get { return (bool)GetValue(AutoEventsViewVisibilityProperty); } |
| 157 | + set { SetValue(AutoEventsViewVisibilityProperty, value); } |
| 158 | + } |
153 | 159 | public TextTransform TextTransform
|
154 | 160 | {
|
155 | 161 | get { return (TextTransform)GetValue(TextTransformProperty); }
|
@@ -263,14 +269,15 @@ public TextType TextType
|
263 | 269 | public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(DayView), Label.TextColorProperty.DefaultValue);
|
264 | 270 | public static readonly BindableProperty VerticalTextAlignmentProperty = BindableProperty.Create(nameof(VerticalTextAlignment), typeof(TextAlignment), typeof(DayView), TextAlignment.Center);
|
265 | 271 | public static readonly BindableProperty AutoSetStyleBasedOnDayStateProperty = BindableProperty.Create(nameof(AutoSetStyleBasedOnDayState), typeof(bool), typeof(DayView), true, propertyChanged: AutoSetStyleBasedOnDayStatePropertyChanged);
|
266 |
| - public static readonly BindableProperty EventsProperty = BindableProperty.Create(nameof(Events), typeof(IEnumerable<IEvent>), typeof(DayView)); |
267 |
| - public static readonly BindableProperty EventsTemplateProperty = BindableProperty.Create(nameof(EventsTemplate), typeof(ControlTemplate), typeof(DayView)); |
268 |
| - public static readonly BindableProperty EventTemplateProperty = BindableProperty.Create(nameof(EventTemplate), typeof(DataTemplate), typeof(DaysView)); |
| 272 | + public static readonly BindableProperty EventsProperty = BindableProperty.Create(nameof(Events), typeof(IEnumerable<IEvent>), typeof(DayView), propertyChanged: EventsPropertyChanged); |
| 273 | + public static readonly BindableProperty EventsTemplateProperty = BindableProperty.Create(nameof(EventsTemplate), typeof(ControlTemplate), typeof(DayView), propertyChanged: EventsTemplatePropertyChanged); |
| 274 | + public static readonly BindableProperty EventTemplateProperty = BindableProperty.Create(nameof(EventTemplate), typeof(DataTemplate), typeof(DaysView), propertyChanged: EventTemplatePropertyChanged); |
269 | 275 | public static readonly BindableProperty EventCornerRadiusProperty = BindableProperty.Create(nameof(EventCornerRadius), typeof(double), typeof(DayView), 100d);
|
270 | 276 | public static readonly BindableProperty EventWidthRequestProperty = BindableProperty.Create(nameof(EventWidthRequest), typeof(double), typeof(DayView), 8d);
|
271 | 277 | public static readonly BindableProperty EventHeightRequestProperty = BindableProperty.Create(nameof(EventHeightRequest), typeof(double), typeof(DayView), 8d);
|
272 | 278 | public static readonly BindableProperty EventsSpacingProperty = BindableProperty.Create(nameof(EventsSpacing), typeof(double), typeof(DayView), 2.5d);
|
273 | 279 | public static readonly BindableProperty EventsOrientationProperty = BindableProperty.Create(nameof(EventsOrientation), typeof(StackOrientation), typeof(DayView), StackOrientation.Horizontal);
|
| 280 | + public static readonly BindableProperty AutoEventsViewVisibilityProperty = BindableProperty.Create(nameof(AutoEventsViewVisibilityProperty), typeof(bool), typeof(DayView), true, propertyChanged: AutoEventsViewVisibilityPropertyChanged); |
274 | 281 | #endregion
|
275 | 282 |
|
276 | 283 | #endregion
|
@@ -345,6 +352,17 @@ public virtual void UpdateView()
|
345 | 352 | }
|
346 | 353 | }
|
347 | 354 | }
|
| 355 | + private void UpdateEventsVisibility() |
| 356 | + { |
| 357 | + if (AutoEventsViewVisibility) |
| 358 | + { |
| 359 | + DayView_Unique_EventsView.IsVisible = Events?.Any() == true; |
| 360 | + } |
| 361 | + } |
| 362 | + private void Events_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
| 363 | + { |
| 364 | + UpdateEventsVisibility(); |
| 365 | + } |
348 | 366 |
|
349 | 367 | #region Bindable Properties Methods
|
350 | 368 | private static object CreateDefaultDayViewCurrentMonthStyle(BindableObject bindable)
|
@@ -474,6 +492,39 @@ private static void AutoSetStyleBasedOnDayStatePropertyChanged(BindableObject bi
|
474 | 492 | control.UpdateView();
|
475 | 493 | }
|
476 | 494 | }
|
| 495 | + private static void EventsPropertyChanged(BindableObject bindable, object oldValue, object newValue) |
| 496 | + { |
| 497 | + DayView control = (DayView)bindable; |
| 498 | + IEnumerable<IEvent> oldEvents = (IEnumerable<IEvent>)oldValue; |
| 499 | + IEnumerable<IEvent> newEvents = (IEnumerable<IEvent>)newValue; |
| 500 | + |
| 501 | + if (oldEvents is INotifyCollectionChanged oldEventsAsCollectionChanged) |
| 502 | + { |
| 503 | + oldEventsAsCollectionChanged.CollectionChanged -= control.Events_CollectionChanged; |
| 504 | + } |
| 505 | + |
| 506 | + if (newEvents is INotifyCollectionChanged newEventsAsCollectionChanged) |
| 507 | + { |
| 508 | + newEventsAsCollectionChanged.CollectionChanged += control.Events_CollectionChanged; |
| 509 | + } |
| 510 | + |
| 511 | + control.UpdateEventsVisibility(); |
| 512 | + } |
| 513 | + private static void EventTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue) |
| 514 | + { |
| 515 | + DayView control = (DayView)bindable; |
| 516 | + control.UpdateEventsVisibility(); |
| 517 | + } |
| 518 | + private static void EventsTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue) |
| 519 | + { |
| 520 | + DayView control = (DayView)bindable; |
| 521 | + control.UpdateEventsVisibility(); |
| 522 | + } |
| 523 | + private static void AutoEventsViewVisibilityPropertyChanged(BindableObject bindable, object oldValue, object newValue) |
| 524 | + { |
| 525 | + DayView control = (DayView)bindable; |
| 526 | + control.UpdateEventsVisibility(); |
| 527 | + } |
477 | 528 | private static object CoerceDayState(BindableObject bindable, object value)
|
478 | 529 | {
|
479 | 530 | DayView control = (DayView)bindable;
|
|
0 commit comments