diff --git a/Wino.Calendar.ViewModels/Data/CalendarItemViewModel.cs b/Wino.Calendar.ViewModels/Data/CalendarItemViewModel.cs
index ff6f17cf..d85be653 100644
--- a/Wino.Calendar.ViewModels/Data/CalendarItemViewModel.cs
+++ b/Wino.Calendar.ViewModels/Data/CalendarItemViewModel.cs
@@ -24,6 +24,10 @@ namespace Wino.Calendar.ViewModels.Data
public ITimePeriod Period => CalendarItem.Period;
+ public bool IsAllDayEvent => ((ICalendarItem)CalendarItem).IsAllDayEvent;
+
+ public bool IsMultiDayEvent => ((ICalendarItem)CalendarItem).IsMultiDayEvent;
+
public CalendarItemViewModel(CalendarItem calendarItem)
{
CalendarItem = calendarItem;
diff --git a/Wino.Calendar/Controls/AllDayItemsControl.xaml b/Wino.Calendar/Controls/AllDayItemsControl.xaml
index 820bd279..23586de3 100644
--- a/Wino.Calendar/Controls/AllDayItemsControl.xaml
+++ b/Wino.Calendar/Controls/AllDayItemsControl.xaml
@@ -4,19 +4,20 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Wino.Calendar.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:data="using:Wino.Calendar.ViewModels.Data"
xmlns:domain="using:Wino.Core.Domain"
+ xmlns:helpers="using:Wino.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
-
-
-
+
+
-
-
+
@@ -47,6 +47,9 @@
+
+
+
diff --git a/Wino.Calendar/Controls/AllDayItemsControl.xaml.cs b/Wino.Calendar/Controls/AllDayItemsControl.xaml.cs
index 4937fd1f..02f38671 100644
--- a/Wino.Calendar/Controls/AllDayItemsControl.xaml.cs
+++ b/Wino.Calendar/Controls/AllDayItemsControl.xaml.cs
@@ -1,19 +1,15 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Collections;
-using Wino.Core.Domain.Interfaces;
namespace Wino.Calendar.Controls
{
public sealed partial class AllDayItemsControl : UserControl
{
- private const string STATE_SummaryView = "SummaryView";
- private const string STATE_FullView = "FullView";
-
#region Dependency Properties
- public static readonly DependencyProperty EventCollectionProperty = DependencyProperty.Register(nameof(EventCollection), typeof(CalendarEventCollection), typeof(AllDayItemsControl), new PropertyMetadata(null, new PropertyChangedCallback(OnAllDayEventsChanged)));
+ public static readonly DependencyProperty EventCollectionProperty = DependencyProperty.Register(nameof(EventCollection), typeof(CalendarEventCollection), typeof(AllDayItemsControl), new PropertyMetadata(null));
public static readonly DependencyProperty AllDayEventTemplateProperty = DependencyProperty.Register(nameof(AllDayEventTemplate), typeof(DataTemplate), typeof(AllDayItemsControl), new PropertyMetadata(null));
public static readonly DependencyProperty RegularEventItemTemplateProperty = DependencyProperty.Register(nameof(RegularEventItemTemplate), typeof(DataTemplate), typeof(AllDayItemsControl), new PropertyMetadata(null));
@@ -51,58 +47,5 @@ namespace Wino.Calendar.Controls
{
InitializeComponent();
}
-
- private static void OnAllDayEventsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is AllDayItemsControl control)
- {
- if (e.OldValue != null && e.OldValue is CalendarEventCollection oldCollection)
- {
- control.UnregisterEventCollectionChanged(oldCollection);
- }
-
- if (e.NewValue != null && e.NewValue is CalendarEventCollection newCollection)
- {
- control.RegisterEventCollectionChanged(newCollection);
- }
-
- control.UpdateCollectionVisuals();
- }
- }
-
- private void RegisterEventCollectionChanged(CalendarEventCollection collection)
- {
- collection.CalendarItemAdded += SingleEventUpdated;
- collection.CalendarItemRemoved += SingleEventUpdated;
-
- collection.CalendarItemsCleared += EventsCleared;
- }
-
- private void UnregisterEventCollectionChanged(CalendarEventCollection collection)
- {
- collection.CalendarItemAdded -= SingleEventUpdated;
- collection.CalendarItemRemoved -= SingleEventUpdated;
-
- collection.CalendarItemsCleared -= EventsCleared;
- }
-
- private void SingleEventUpdated(object sender, ICalendarItem calendarItem) => UpdateCollectionVisuals();
- private void EventsCleared(object sender, System.EventArgs e) => UpdateCollectionVisuals();
-
- private void UpdateCollectionVisuals()
- {
- if (EventCollection == null) return;
-
- if (EventCollection.AllDayEvents.Count > 1)
- {
- // Summarize
- VisualStateManager.GoToState(this, STATE_SummaryView, false);
- }
- else
- {
- // Full view.
- VisualStateManager.GoToState(this, STATE_FullView, false);
- }
- }
}
}
diff --git a/Wino.Calendar/Controls/CalendarItemControl.xaml b/Wino.Calendar/Controls/CalendarItemControl.xaml
new file mode 100644
index 00000000..7f4c99e3
--- /dev/null
+++ b/Wino.Calendar/Controls/CalendarItemControl.xaml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Wino.Calendar/Controls/CalendarItemControl.xaml.cs b/Wino.Calendar/Controls/CalendarItemControl.xaml.cs
new file mode 100644
index 00000000..856f4065
--- /dev/null
+++ b/Wino.Calendar/Controls/CalendarItemControl.xaml.cs
@@ -0,0 +1,49 @@
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Wino.Calendar.ViewModels.Data;
+using Wino.Core.Domain.Interfaces;
+
+namespace Wino.Calendar.Controls
+{
+ public sealed partial class CalendarItemControl : UserControl
+ {
+ public ICalendarItem CalendarItem
+ {
+ get { return (CalendarItemViewModel)GetValue(CalendarItemProperty); }
+ set { SetValue(CalendarItemProperty, value); }
+ }
+
+ public static readonly DependencyProperty CalendarItemProperty = DependencyProperty.Register(nameof(CalendarItem), typeof(ICalendarItem), typeof(CalendarItemControl), new PropertyMetadata(null, new PropertyChangedCallback(OnCalendarItemChanged)));
+
+ public CalendarItemControl()
+ {
+ InitializeComponent();
+ }
+
+ private static void OnCalendarItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is CalendarItemControl control)
+ {
+ control.UpdateVisualStates();
+ }
+ }
+
+ private void UpdateVisualStates()
+ {
+ if (CalendarItem == null) return;
+
+ if (CalendarItem.IsAllDayEvent)
+ {
+ VisualStateManager.GoToState(this, "AllDayEvent", true);
+ }
+ else if (CalendarItem.IsMultiDayEvent)
+ {
+ VisualStateManager.GoToState(this, "MultiDayEvent", true);
+ }
+ else
+ {
+ VisualStateManager.GoToState(this, "RegularEvent", true);
+ }
+ }
+ }
+}
diff --git a/Wino.Calendar/Styles/WinoCalendarResources.xaml b/Wino.Calendar/Styles/WinoCalendarResources.xaml
index 573383d1..016f3516 100644
--- a/Wino.Calendar/Styles/WinoCalendarResources.xaml
+++ b/Wino.Calendar/Styles/WinoCalendarResources.xaml
@@ -13,19 +13,7 @@
-
-
-
+
@@ -46,6 +34,11 @@
+
+
+
+
+
@@ -229,12 +222,12 @@
-
+ RegularEventItemTemplate="{StaticResource CalendarItemViewModelItemTemplate}" />
diff --git a/Wino.Calendar/Wino.Calendar.csproj b/Wino.Calendar/Wino.Calendar.csproj
index 5fa38ed2..878b75cf 100644
--- a/Wino.Calendar/Wino.Calendar.csproj
+++ b/Wino.Calendar/Wino.Calendar.csproj
@@ -139,6 +139,9 @@
AllDayItemsControl.xaml
+
+ CalendarItemControl.xaml
+
@@ -250,6 +253,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
MSBuild:Compile
Designer
diff --git a/Wino.Core.Domain/Collections/CalendarEventCollection.cs b/Wino.Core.Domain/Collections/CalendarEventCollection.cs
index 1ee11064..d31875a7 100644
--- a/Wino.Core.Domain/Collections/CalendarEventCollection.cs
+++ b/Wino.Core.Domain/Collections/CalendarEventCollection.cs
@@ -26,9 +26,10 @@ namespace Wino.Core.Domain.Collections
public CalendarEventCollection(ITimePeriod period)
{
+ Period = period;
+
RegularEvents = new ReadOnlyObservableCollection(_internalRegularEvents);
AllDayEvents = new ReadOnlyObservableCollection(_internalAllDayEvents);
- Period = period;
}
public bool HasCalendarEvent(AccountCalendar accountCalendar)
diff --git a/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs b/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs
index 2f7236e6..af24d146 100644
--- a/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs
+++ b/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs
@@ -38,6 +38,22 @@ namespace Wino.Core.Domain.Entities.Calendar
}
}
+ public bool IsAllDayEvent
+ {
+ get
+ {
+ return StartDate.TimeOfDay == TimeSpan.Zero && EndDate.TimeOfDay == TimeSpan.Zero;
+ }
+ }
+
+ public bool IsMultiDayEvent
+ {
+ get
+ {
+ return StartDate.Date != EndDate.Date;
+ }
+ }
+
public double DurationInSeconds { get; set; }
public string Recurrence { get; set; }
diff --git a/Wino.Core.Domain/Interfaces/ICalendarItem.cs b/Wino.Core.Domain/Interfaces/ICalendarItem.cs
index f548ac8d..483ef7f8 100644
--- a/Wino.Core.Domain/Interfaces/ICalendarItem.cs
+++ b/Wino.Core.Domain/Interfaces/ICalendarItem.cs
@@ -12,5 +12,7 @@ namespace Wino.Core.Domain.Interfaces
DateTime EndDate { get; }
double DurationInSeconds { get; set; }
ITimePeriod Period { get; }
+ bool IsAllDayEvent { get; }
+ bool IsMultiDayEvent { get; }
}
}
diff --git a/Wino.Core.UWP/Helpers/XamlHelpers.cs b/Wino.Core.UWP/Helpers/XamlHelpers.cs
index 8587d804..2cdb1e1a 100644
--- a/Wino.Core.UWP/Helpers/XamlHelpers.cs
+++ b/Wino.Core.UWP/Helpers/XamlHelpers.cs
@@ -10,7 +10,9 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Wino.Core.Domain;
+using Wino.Core.Domain.Collections;
using Wino.Core.Domain.Enums;
+using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.UWP.Controls;
@@ -23,6 +25,12 @@ namespace Wino.Helpers
#region Converters
+ public static bool IsMultiple(int count) => count > 1;
+ public static bool ReverseIsMultiple(int count) => count < 1;
+
+ public static ICalendarItem GetFirstAllDayEvent(CalendarEventCollection collection)
+ => collection.AllDayEvents.FirstOrDefault();
+
public static Visibility ReverseBoolToVisibilityConverter(bool value) => value ? Visibility.Collapsed : Visibility.Visible;
public static Visibility ReverseVisibilityConverter(Visibility visibility) => visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
public static bool ReverseBoolConverter(bool value) => !value;