Some adjustments for all day items control. Removed the leaking part.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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">
|
||||
|
||||
<Grid>
|
||||
<ScrollViewer x:Name="PART_AllDayItemsListScrollHost">
|
||||
<ItemsControl
|
||||
x:Name="PART_AllDayItemsList"
|
||||
ItemTemplate="{x:Bind AllDayEventTemplate}"
|
||||
ItemsSource="{x:Bind EventCollection.AllDayEvents}" />
|
||||
</ScrollViewer>
|
||||
<controls:CalendarItemControl
|
||||
x:Name="SingleAllDayEventHolder"
|
||||
CalendarItem="{x:Bind helpers:XamlHelpers.GetFirstAllDayEvent(EventCollection), Mode=OneWay}"
|
||||
Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(EventCollection.AllDayEvents.Count), Mode=OneWay}" />
|
||||
|
||||
<Button
|
||||
x:Name="AllDayItemsSummaryButton"
|
||||
HorizontalAlignment="Stretch"
|
||||
@@ -36,8 +37,7 @@
|
||||
<VisualState x:Name="FullView" />
|
||||
<VisualState x:Name="SummaryView">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="PART_AllDayItemsListScrollHost.Visibility" Value="Collapsed" />
|
||||
<Setter Target="PART_AllDayItemsList.Visibility" Value="Collapsed" />
|
||||
<Setter Target="SingleAllDayEventHolder.Visibility" Value="Collapsed" />
|
||||
<Setter Target="AllDayItemsSummaryButton.Visibility" Value="Visible" />
|
||||
<Setter Target="AllDayItemsSummaryButton.Content">
|
||||
<Setter.Value>
|
||||
@@ -47,6 +47,9 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</VisualState.Setters>
|
||||
<VisualState.StateTriggers>
|
||||
<StateTrigger IsActive="{x:Bind helpers:XamlHelpers.IsMultiple(EventCollection.AllDayEvents.Count), Mode=OneWay, FallbackValue='False'}" />
|
||||
</VisualState.StateTriggers>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
Wino.Calendar/Controls/CalendarItemControl.xaml
Normal file
48
Wino.Calendar/Controls/CalendarItemControl.xaml
Normal file
@@ -0,0 +1,48 @@
|
||||
<UserControl
|
||||
x:Class="Wino.Calendar.Controls.CalendarItemControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:helpers="using:Wino.Helpers"
|
||||
xmlns:local="using:Wino.Calendar.Controls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid
|
||||
x:Name="MainGrid"
|
||||
BorderBrush="{ThemeResource CalendarSeperatorBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="6">
|
||||
<Grid x:Name="MainBackground" Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(CalendarItem.AssignedCalendar.BackgroundColorHex), Mode=OneWay}" />
|
||||
<TextBlock
|
||||
x:Name="EventTitleTextblock"
|
||||
Margin="2,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{x:Bind helpers:XamlHelpers.GetReadableTextColor(CalendarItem.AssignedCalendar.BackgroundColorHex), Mode=OneWay}"
|
||||
Text="{x:Bind CalendarItem.Title}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="EventDurationStates">
|
||||
<VisualState x:Name="RegularEvent" />
|
||||
<VisualState x:Name="AllDayEvent">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="MainGrid.MinHeight" Value="25" />
|
||||
<Setter Target="EventTitleTextblock.Margin" Value="6,0" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
|
||||
<VisualState x:Name="MultiDayEvent">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="MainBackground.Opacity" Value="0.6" />
|
||||
<Setter Target="MainGrid.CornerRadius" Value="0" />
|
||||
<Setter Target="MainGrid.BorderThickness" Value="0.5" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
49
Wino.Calendar/Controls/CalendarItemControl.xaml.cs
Normal file
49
Wino.Calendar/Controls/CalendarItemControl.xaml.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,19 +13,7 @@
|
||||
|
||||
<!-- Default Calendar Item View Model Template -->
|
||||
<DataTemplate x:Key="CalendarItemViewModelItemTemplate" x:DataType="data:CalendarItemViewModel">
|
||||
<Grid
|
||||
Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(AssignedCalendar.BackgroundColorHex), Mode=OneWay}"
|
||||
BorderBrush="{ThemeResource CalendarSeperatorBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="6">
|
||||
<TextBlock
|
||||
Margin="2,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{x:Bind helpers:XamlHelpers.GetReadableTextColor(AssignedCalendar.BackgroundColorHex), Mode=OneWay}"
|
||||
Text="{x:Bind CalendarItem.Title}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
<controls:CalendarItemControl CalendarItem="{x:Bind}" />
|
||||
</DataTemplate>
|
||||
|
||||
<!-- All-Day Event template -->
|
||||
@@ -46,6 +34,11 @@
|
||||
<!-- Vertical panel that renders items on canvas. -->
|
||||
<DataTemplate x:Key="DayCalendarItemVerticalRenderTemplate" x:DataType="models:CalendarDayModel">
|
||||
<ItemsControl ItemTemplate="{StaticResource CalendarItemViewModelItemTemplate}" ItemsSource="{x:Bind EventsCollection.RegularEvents}">
|
||||
<ItemsControl.ItemContainerTransitions>
|
||||
<TransitionCollection>
|
||||
<PaneThemeTransition Edge="Left" />
|
||||
</TransitionCollection>
|
||||
</ItemsControl.ItemContainerTransitions>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<controls:WinoCalendarPanel HourHeight="{Binding Path=CalendarRenderOptions.CalendarSettings.HourHeight}" Period="{Binding Path=Period}" />
|
||||
@@ -229,12 +222,12 @@
|
||||
<!-- All-Day Events -->
|
||||
|
||||
<!-- TODO: This control leaks. -->
|
||||
<!--<controls:AllDayItemsControl
|
||||
<controls:AllDayItemsControl
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
AllDayEventTemplate="{StaticResource AllDayEventItemTemplate}"
|
||||
AllDayEventTemplate="{StaticResource CalendarItemViewModelItemTemplate}"
|
||||
EventCollection="{Binding EventsCollection}"
|
||||
RegularEventItemTemplate="{StaticResource CalendarItemViewModelItemTemplate}" />-->
|
||||
RegularEventItemTemplate="{StaticResource CalendarItemViewModelItemTemplate}" />
|
||||
</Grid>
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
|
||||
@@ -139,6 +139,9 @@
|
||||
<Compile Include="Controls\AllDayItemsControl.xaml.cs">
|
||||
<DependentUpon>AllDayItemsControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\CalendarItemControl.xaml.cs">
|
||||
<DependentUpon>CalendarItemControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\CustomCalendarFlipView.cs" />
|
||||
<Compile Include="Controls\DayColumnControl.cs" />
|
||||
<Compile Include="Controls\DayHeaderControl.cs" />
|
||||
@@ -250,6 +253,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Controls\CalendarItemControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
@@ -26,9 +26,10 @@ namespace Wino.Core.Domain.Collections
|
||||
|
||||
public CalendarEventCollection(ITimePeriod period)
|
||||
{
|
||||
Period = period;
|
||||
|
||||
RegularEvents = new ReadOnlyObservableCollection<ICalendarItem>(_internalRegularEvents);
|
||||
AllDayEvents = new ReadOnlyObservableCollection<ICalendarItem>(_internalAllDayEvents);
|
||||
Period = period;
|
||||
}
|
||||
|
||||
public bool HasCalendarEvent(AccountCalendar accountCalendar)
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user