Displaying events and all-day events.
This commit is contained in:
@@ -20,9 +20,8 @@
|
||||
<ResourceDictionary Source="Styles/CalendarRenderStyles.xaml" />
|
||||
|
||||
<ResourceDictionary Source="Styles/CalendarDayItemsControl.xaml" />
|
||||
<ResourceDictionary Source="Styles/DayHeaderControl.xaml" />
|
||||
<styles:DayColumnControlResources />
|
||||
<ResourceDictionary Source="Styles/WinoDayTimelineCanvas.xaml" />
|
||||
<ResourceDictionary Source="Styles/DayColumnControl.xaml" />
|
||||
<ResourceDictionary Source="Styles/WinoCalendarView.xaml" />
|
||||
<ResourceDictionary Source="Styles/WinoCalendarTypeSelectorControl.xaml" />
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace Wino.Calendar.Controls
|
||||
{
|
||||
if (e.OldValue != null && e.OldValue is CalendarDayModel oldCalendarDayModel)
|
||||
{
|
||||
control.DetachCollection(oldCalendarDayModel.Events);
|
||||
control.DetachCollection(oldCalendarDayModel.EventsCollection);
|
||||
}
|
||||
|
||||
if (e.NewValue != null && e.NewValue is CalendarDayModel newCalendarDayModel)
|
||||
{
|
||||
control.AttachCollection(newCalendarDayModel.Events);
|
||||
control.AttachCollection(newCalendarDayModel.EventsCollection);
|
||||
}
|
||||
|
||||
control.ResetItems();
|
||||
@@ -109,13 +109,13 @@ namespace Wino.Calendar.Controls
|
||||
|
||||
private void RenderCalendarItems()
|
||||
{
|
||||
if (DayModel == null || DayModel.Events == null || DayModel.Events.Count == 0)
|
||||
if (DayModel == null || DayModel.EventsCollection == null || DayModel.EventsCollection.Count == 0)
|
||||
{
|
||||
ResetItems();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in DayModel.Events)
|
||||
foreach (var item in DayModel.EventsCollection)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace Wino.Calendar.Controls
|
||||
// We need to listen for new events being added or removed from the collection to reset measurements.
|
||||
if (e.OldValue is CalendarDayModel oldDayModel)
|
||||
{
|
||||
control.DetachCollection(oldDayModel.Events);
|
||||
control.DetachCollection(oldDayModel.EventsCollection);
|
||||
}
|
||||
|
||||
if (e.NewValue is CalendarDayModel newDayModel)
|
||||
{
|
||||
control.AttachCollection(newDayModel.Events);
|
||||
control.AttachCollection(newDayModel.EventsCollection);
|
||||
}
|
||||
|
||||
control.ResetMeasurements();
|
||||
@@ -114,12 +114,17 @@ namespace Wino.Calendar.Controls
|
||||
|
||||
var calendarControls = Children.Cast<CalendarItemControl>();
|
||||
|
||||
if (_measurements.Count == 0 && DayModel.Events.Count > 0)
|
||||
// We need to exclude all-day events from the layout algorithm.
|
||||
// All-day events are displayed in a separate panel.
|
||||
|
||||
calendarControls = calendarControls.Where(x => x.Item.DurationInMinutes != 1440);
|
||||
|
||||
if (_measurements.Count == 0 && DayModel.EventsCollection.Count > 0)
|
||||
{
|
||||
// We keep track of this collection when event is added/removed/reset etc.
|
||||
// So if the collection is empty, we must fill it up again for proper calculations.
|
||||
|
||||
LayoutEvents(DayModel.Events);
|
||||
LayoutEvents(DayModel.EventsCollection);
|
||||
}
|
||||
|
||||
foreach (var child in calendarControls)
|
||||
@@ -129,9 +134,7 @@ namespace Wino.Calendar.Controls
|
||||
|
||||
var childMeasurement = _measurements[child.Item.Id];
|
||||
|
||||
// TODO Math.Max(0, GetChildHeight(child.Item.StartTime, child.Item.EndTime));
|
||||
// Recurring events may not have an end time. We need to calculate the height based on the start time and duration.
|
||||
double childHeight = 50;
|
||||
double childHeight = Math.Max(0, GetChildHeight(child.Item.StartTime, child.Item.StartTime.AddMinutes(child.Item.DurationInMinutes)));
|
||||
double childWidth = Math.Max(0, GetChildWidth(childMeasurement, finalSize.Width));
|
||||
double childTop = Math.Max(0, GetChildTopMargin(child.Item.StartTime, availableHeight));
|
||||
double childLeft = Math.Max(0, GetChildLeftMargin(childMeasurement, availableWidth));
|
||||
@@ -139,12 +142,10 @@ namespace Wino.Calendar.Controls
|
||||
bool isHorizontallyLastItem = childMeasurement.Right == 1;
|
||||
|
||||
// Add additional right margin to items that falls on the right edge of the panel.
|
||||
// Max of 5% of the width or 20px.
|
||||
// Max of 5% of the width or 20px max.
|
||||
var extraRightMargin = isHorizontallyLastItem ? Math.Max(LastItemRightExtraMargin, finalSize.Width * 5 / 100) : 0;
|
||||
|
||||
var finalChildWidth = childWidth - extraRightMargin;
|
||||
|
||||
if (finalChildWidth < 0) finalChildWidth = 1;
|
||||
if (childWidth < 0) childWidth = 1;
|
||||
|
||||
child.Measure(new Size(childWidth, childHeight));
|
||||
|
||||
@@ -178,6 +179,8 @@ namespace Wino.Calendar.Controls
|
||||
|
||||
foreach (var ev in events.OrderBy(ev => ev.Period.Start).ThenBy(ev => ev.Period.End))
|
||||
{
|
||||
if (ev.Period.Duration.TotalMinutes == 1440) continue;
|
||||
|
||||
if (ev.Period.Start >= lastEventEnding)
|
||||
{
|
||||
PackEvents(columns);
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{x:Bind Item.Title, Mode=OneWay}" />
|
||||
Text="{x:Bind Item.Title, Mode=OneWay}"
|
||||
TextWrapping="WrapWholeWords" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<ResourceDictionary
|
||||
x:Class="Wino.Calendar.Styles.DayColumnControlResources"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:Wino.Calendar.Controls">
|
||||
|
||||
xmlns:controls="using:Wino.Calendar.Controls"
|
||||
xmlns:data="using:Wino.Calendar.ViewModels.Data"
|
||||
xmlns:interfaces="using:Wino.Core.Domain.Interfaces"
|
||||
xmlns:local="using:Wino.Calendar.Styles">
|
||||
<!-- Top column header DayColumnControl -->
|
||||
<Style TargetType="controls:DayColumnControl">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:DayColumnControl">
|
||||
<Grid MinHeight="100" MaxHeight="150">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="7" />
|
||||
@@ -62,11 +65,20 @@
|
||||
<!-- Extras -->
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Right" />
|
||||
|
||||
<!-- Events -->
|
||||
<!-- All-Day Events -->
|
||||
<ScrollViewer
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
VerticalScrollBarVisibility="Hidden" />
|
||||
VerticalScrollBarVisibility="Hidden">
|
||||
<ItemsControl ItemsSource="{Binding EventsCollection.AllDayEvents, Mode=OneWay}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<!-- All-Day Event template -->
|
||||
<DataTemplate x:DataType="interfaces:ICalendarItem">
|
||||
<TextBlock Text="{x:Bind Title}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
@@ -89,5 +101,4 @@
|
||||
</Style>
|
||||
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
12
Wino.Calendar/Styles/DayColumnControlResources.xaml.cs
Normal file
12
Wino.Calendar/Styles/DayColumnControlResources.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace Wino.Calendar.Styles
|
||||
{
|
||||
partial class DayColumnControlResources : ResourceDictionary
|
||||
{
|
||||
public DayColumnControlResources()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,10 @@
|
||||
ItemsSource="{x:Bind CalendarDays}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:CalendarDayModel">
|
||||
<controls:DayColumnControl DayModel="{x:Bind}" />
|
||||
<controls:DayColumnControl
|
||||
MinHeight="100"
|
||||
MaxHeight="200"
|
||||
DayModel="{x:Bind}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.ItemsPanel>
|
||||
|
||||
@@ -158,6 +158,9 @@
|
||||
<Compile Include="Services\ProviderService.cs" />
|
||||
<Compile Include="Services\SettingsBuilderService.cs" />
|
||||
<Compile Include="Styles\CalendarItemControlResources.xaml.cs" />
|
||||
<Compile Include="Styles\DayColumnControlResources.xaml.cs">
|
||||
<DependentUpon>DayColumnControlResources.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Styles\WinoCalendarResources.xaml.cs" />
|
||||
<Compile Include="Views\Abstract\AccountManagementPageAbstract.cs" />
|
||||
<Compile Include="Views\Abstract\AppShellAbstract.cs" />
|
||||
@@ -261,9 +264,9 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Styles\DayColumnControl.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<Page Include="Styles\DayColumnControlResources.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Styles\DayHeaderControl.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
Reference in New Issue
Block a user