Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of getting/reading Appointments to the Appointments sample #1049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Samples/Appointments/cs/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="appointments" />
</Capabilities>
</Package>
41 changes: 40 additions & 1 deletion Samples/Appointments/cs/Scenario5_Show.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.ApplicationModel.Appointments;
using System.Linq;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace SDKTemplate
{
Expand All @@ -23,8 +27,42 @@ public sealed partial class Scenario5_Show : Page
public Scenario5_Show()
{
this.InitializeComponent();
this.DataContext = this;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var ignore = AppointmentGet();
}

private async Task AppointmentGet()
{
var dateToShow = DateTime.Now.AddDays(1);
var duration = TimeSpan.FromHours(24);

AppointmentStore calendar = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

// Specify which values to retrieve
FindAppointmentsOptions options = new FindAppointmentsOptions();
options.FetchProperties.Add(AppointmentProperties.Subject);
options.FetchProperties.Add(AppointmentProperties.StartTime);
options.FetchProperties.Add(AppointmentProperties.Duration);
options.FetchProperties.Add(AppointmentProperties.AllDay);
options.FetchProperties.Add(AppointmentProperties.Details);
options.FetchProperties.Add(AppointmentProperties.DetailsKind);

var iteratingAppointments = await calendar.FindAppointmentsAsync(dateToShow, duration, options);
var items = from a in iteratingAppointments select a;

await rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() => { items.ToList().ForEach(a => this.appointments.Add(a)); }
);
}

private ObservableCollection<Appointment> appointments = new ObservableCollection<Appointment>();
public ObservableCollection<Appointment> Appointments => appointments;

/// <summary>
/// Show the default appointment provider at a point in time 24 hours from now.
/// </summary>
Expand All @@ -33,7 +71,8 @@ public Scenario5_Show()
private async void Show_Click(object sender, RoutedEventArgs e)
{
var dateToShow = DateTime.Now.AddDays(1);
var duration = TimeSpan.FromHours(1);
var duration = TimeSpan.FromHours(24);

await Windows.ApplicationModel.Appointments.AppointmentManager.ShowTimeFrameAsync(dateToShow, duration);
rootPage.NotifyUser("The default appointments provider should have appeared on screen.", NotifyType.StatusMessage);
}
Expand Down
45 changes: 44 additions & 1 deletion Samples/Appointments/shared/Scenario5_Show.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,50 @@
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
Shows the default appointments provider app at a particular time and date.
</TextBlock>
<Button x:Name="ShowTimeFrameButton" Content="Show 24 hours from now" Margin="0,10,0,0" Click="Show_Click"/>
<Button x:Name="ShowTimeFrameButton" Content="Show Calendar View of 24 hours from now" Margin="0,10,0,0" Click="Show_Click"/>

<TextBlock Padding="30" FontSize="30">List of Calendar events 24 hours from now</TextBlock>
<GridView ItemsSource="{Binding Appointments}"
IsItemClickEnabled="True"
IsSwipeEnabled="true"
SelectionMode="Single">
<GridView.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="Subject"/>
<TextBlock Grid.Column="1" Text="StartTime"/>
<TextBlock Grid.Column="2" Text="Duration"/>
<TextBlock Grid.Column="3" Text="AllDay?"/>
</Grid>
</DataTemplate>
</GridView.HeaderTemplate>

<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="{Binding Subject}"/>
<TextBlock Grid.Column="1" Text="{Binding StartTime}"/>
<TextBlock Grid.Column="2" Text="{Binding Duration}"/>
<TextBlock Grid.Column="3" Text="{Binding AllDay}"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>

</StackPanel>
</Grid>
</Grid>
Expand Down