Skip to content

Commit 3ca6264

Browse files
Experimental attribute for GraphPresenter and sample updates (#148)
* Added experimental attributes to GraphPresenter and QueryOption * Moved GraphPresenter samples into separate pages and added another for OneDrive * Converting converters into simple methods
1 parent 1f01026 commit 3ca6264

17 files changed

+725
-337
lines changed

CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading;
1010
using Microsoft.Graph;
1111
using Microsoft.Toolkit.Uwp;
12+
using Windows.Foundation.Metadata;
1213
using Windows.System;
1314
using Windows.UI.Xaml;
1415
using Windows.UI.Xaml.Controls;
@@ -18,9 +19,9 @@ namespace CommunityToolkit.Graph.Uwp.Controls
1819
/// <summary>
1920
/// Specialized <see cref="ContentPresenter"/> to fetch and display data from the Microsoft Graph.
2021
/// </summary>
22+
[Experimental]
2123
public class GraphPresenter : ContentPresenter
2224
{
23-
2425
/// <summary>
2526
/// Identifies the <see cref="RequestBuilder"/> dependency property.
2627
/// </summary>

CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/QueryOption.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
using System.Linq;
88
using System.Text;
99
using System.Threading.Tasks;
10+
using Windows.Foundation.Metadata;
1011
using Windows.UI.Xaml;
1112

1213
namespace CommunityToolkit.Graph.Uwp.Controls
1314
{
1415
/// <summary>
1516
/// XAML Proxy for <see cref="Microsoft.Graph.QueryOption"/>.
1617
/// </summary>
18+
[Experimental]
1719
public sealed class QueryOption
1820
{
1921
/// <inheritdoc cref="Microsoft.Graph.Option.Name"/>

SampleTest/SampleTest.csproj

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,20 @@
126126
<Compile Include="Samples\GraphPresenterSample.xaml.cs">
127127
<DependentUpon>GraphPresenterSample.xaml</DependentUpon>
128128
</Compile>
129-
<Compile Include="Samples\OneDriveStorageSample.xaml.cs">
130-
<DependentUpon>OneDriveStorageSample.xaml</DependentUpon>
129+
<Compile Include="Samples\GraphPresenter\CalendarViewSample.xaml.cs">
130+
<DependentUpon>CalendarViewSample.xaml</DependentUpon>
131+
</Compile>
132+
<Compile Include="Samples\GraphPresenter\MailMessagesSample.xaml.cs">
133+
<DependentUpon>MailMessagesSample.xaml</DependentUpon>
134+
</Compile>
135+
<Compile Include="Samples\GraphPresenter\OneDriveSample.xaml.cs">
136+
<DependentUpon>OneDriveSample.xaml</DependentUpon>
137+
</Compile>
138+
<Compile Include="Samples\GraphPresenter\PlannerTasksSample.xaml.cs">
139+
<DependentUpon>PlannerTasksSample.xaml</DependentUpon>
140+
</Compile>
141+
<Compile Include="Samples\GraphPresenter\TeamsChannelMessagesSample.xaml.cs">
142+
<DependentUpon>TeamsChannelMessagesSample.xaml</DependentUpon>
131143
</Compile>
132144
<Compile Include="Samples\PeoplePickerSample.xaml.cs">
133145
<DependentUpon>PeoplePickerSample.xaml</DependentUpon>
@@ -166,7 +178,23 @@
166178
<SubType>Designer</SubType>
167179
<Generator>MSBuild:Compile</Generator>
168180
</Page>
169-
<Page Include="Samples\OneDriveStorageSample.xaml">
181+
<Page Include="Samples\GraphPresenter\CalendarViewSample.xaml">
182+
<SubType>Designer</SubType>
183+
<Generator>MSBuild:Compile</Generator>
184+
</Page>
185+
<Page Include="Samples\GraphPresenter\MailMessagesSample.xaml">
186+
<SubType>Designer</SubType>
187+
<Generator>MSBuild:Compile</Generator>
188+
</Page>
189+
<Page Include="Samples\GraphPresenter\OneDriveSample.xaml">
190+
<SubType>Designer</SubType>
191+
<Generator>MSBuild:Compile</Generator>
192+
</Page>
193+
<Page Include="Samples\GraphPresenter\PlannerTasksSample.xaml">
194+
<SubType>Designer</SubType>
195+
<Generator>MSBuild:Compile</Generator>
196+
</Page>
197+
<Page Include="Samples\GraphPresenter\TeamsChannelMessagesSample.xaml">
170198
<SubType>Designer</SubType>
171199
<Generator>MSBuild:Compile</Generator>
172200
</Page>
@@ -186,6 +214,12 @@
186214
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
187215
<Version>6.2.12</Version>
188216
</PackageReference>
217+
<PackageReference Include="Microsoft.Toolkit.Mvvm">
218+
<Version>7.1.0-preview1</Version>
219+
</PackageReference>
220+
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
221+
<Version>7.1.0-preview1</Version>
222+
</PackageReference>
189223
</ItemGroup>
190224
<ItemGroup>
191225
<ProjectReference Include="..\CommunityToolkit.Authentication.Msal\CommunityToolkit.Authentication.Msal.csproj">
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Page
2+
x:Class="SampleTest.Samples.GraphPresenter.CalendarViewSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:SampleTest.Samples.GraphPresenter"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls"
9+
xmlns:global="using:System.Globalization"
10+
xmlns:graph="using:Microsoft.Graph"
11+
xmlns:samples="using:SampleTest.Samples"
12+
mc:Ignorable="d"
13+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
14+
15+
<Grid>
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="Auto" />
18+
<RowDefinition Height="*" />
19+
</Grid.RowDefinitions>
20+
<StackPanel>
21+
<TextBlock>
22+
The following example shows the `Me.CalendarView` API.
23+
</TextBlock>
24+
<TextBlock Margin="0,8,0,0" FontWeight="Bold">
25+
My Upcoming Calendar Events:
26+
</TextBlock>
27+
</StackPanel>
28+
<controls:GraphPresenter
29+
Grid.Row="1"
30+
IsCollection="True"
31+
OrderBy="start/dateTime"
32+
RequestBuilder="{x:Bind CalendarViewRequestBuilder, Mode=OneWay}"
33+
ResponseType="graph:Event">
34+
<controls:GraphPresenter.QueryOptions>
35+
<!-- Need to create separate Properties as multiple functions not supported in x:Bind see https://github.com/microsoft/microsoft-ui-xaml/issues/2407 -->
36+
<controls:QueryOption Name="startDateTime" Value="{x:Bind Today.ToString('o', global:CultureInfo.InvariantCulture)}" />
37+
<controls:QueryOption Name="endDateTime" Value="{x:Bind ThreeDaysFromNow.ToString('o', global:CultureInfo.InvariantCulture)}" />
38+
</controls:GraphPresenter.QueryOptions>
39+
<controls:GraphPresenter.ContentTemplate>
40+
<DataTemplate>
41+
<!-- Return result is a collection of Event's as we used 'IsCollection', so bind that first. -->
42+
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto">
43+
<ItemsControl ItemsSource="{Binding}">
44+
<ItemsControl.ItemTemplate>
45+
<DataTemplate x:DataType="graph:Event">
46+
<StackPanel>
47+
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{Binding Subject}" />
48+
<TextBlock FontWeight="Bold">
49+
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(Start), Mode=OneWay}" />
50+
<Run>-</Run>
51+
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(End), Mode=OneWay}" />
52+
</TextBlock>
53+
<TextBlock>
54+
<Run FontFamily="Segoe MDL2 Assets" Text="&#xE707;" />
55+
<Run />
56+
<Run Text="{x:Bind Location.DisplayName, Mode=OneWay}" />
57+
</TextBlock>
58+
</StackPanel>
59+
</DataTemplate>
60+
</ItemsControl.ItemTemplate>
61+
<ItemsControl.ItemContainerStyle>
62+
<Style TargetType="ContentPresenter">
63+
<Setter Property="Margin" Value="0,8,0,8" />
64+
</Style>
65+
</ItemsControl.ItemContainerStyle>
66+
</ItemsControl>
67+
</ScrollViewer>
68+
</DataTemplate>
69+
</controls:GraphPresenter.ContentTemplate>
70+
</controls:GraphPresenter>
71+
</Grid>
72+
</Page>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using CommunityToolkit.Authentication;
7+
using CommunityToolkit.Graph.Extensions;
8+
using Microsoft.Graph;
9+
using Microsoft.Graph.Extensions;
10+
using Windows.UI.Xaml.Controls;
11+
12+
namespace SampleTest.Samples.GraphPresenter
13+
{
14+
public sealed partial class CalendarViewSample : Page
15+
{
16+
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
17+
public DateTime Today => DateTimeOffset.Now.Date.ToUniversalTime();
18+
19+
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
20+
public DateTime ThreeDaysFromNow => Today.AddDays(3);
21+
22+
public IBaseRequestBuilder CalendarViewRequestBuilder { get; set; }
23+
24+
public CalendarViewSample()
25+
{
26+
this.InitializeComponent();
27+
28+
ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
29+
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
30+
}
31+
32+
private void OnProviderUpdated(object sender, IProvider provider)
33+
{
34+
if (provider == null)
35+
{
36+
ClearRequestBuilders();
37+
}
38+
}
39+
40+
private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
41+
{
42+
if (e.NewState == ProviderState.SignedIn)
43+
{
44+
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
45+
46+
CalendarViewRequestBuilder = graphClient.Me.CalendarView;
47+
}
48+
else
49+
{
50+
ClearRequestBuilders();
51+
}
52+
}
53+
54+
private void ClearRequestBuilders()
55+
{
56+
CalendarViewRequestBuilder = null;
57+
}
58+
}
59+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<Page
2+
x:Class="SampleTest.Samples.GraphPresenter.MailMessagesSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:SampleTest.Samples.GraphPresenter"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls"
9+
xmlns:graph="using:Microsoft.Graph"
10+
mc:Ignorable="d"
11+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
12+
13+
<Grid>
14+
<Grid.RowDefinitions>
15+
<RowDefinition Height="Auto" />
16+
<RowDefinition Height="*" />
17+
</Grid.RowDefinitions>
18+
<StackPanel>
19+
<TextBlock>
20+
The following example shows the `Me.Messages` API for getting a user's inbox mail messages.
21+
</TextBlock>
22+
<TextBlock Margin="0,8,0,0" FontWeight="Bold">
23+
My Messages:
24+
</TextBlock>
25+
</StackPanel>
26+
<controls:GraphPresenter
27+
Grid.Row="1"
28+
IsCollection="True"
29+
RequestBuilder="{x:Bind MessagesRequestBuilder, Mode=OneWay}"
30+
ResponseType="graph:Message">
31+
<controls:GraphPresenter.ContentTemplate>
32+
<DataTemplate>
33+
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto">
34+
<ItemsControl ItemsSource="{Binding}">
35+
<ItemsControl.ItemTemplate>
36+
<DataTemplate x:DataType="graph:Message">
37+
<StackPanel>
38+
<controls:PersonView
39+
Margin="-4"
40+
PersonQuery="{x:Bind Sender.EmailAddress.Address}"
41+
PersonViewType="OneLine" />
42+
<TextBlock
43+
Padding="0"
44+
Style="{StaticResource BaseTextBlockStyle}"
45+
Text="{x:Bind Subject}" />
46+
<TextBlock
47+
Text="{x:Bind local:MailMessagesSample.RemoveWhitespace(BodyPreview)}"
48+
TextWrapping="WrapWholeWords" />
49+
</StackPanel>
50+
</DataTemplate>
51+
</ItemsControl.ItemTemplate>
52+
<ItemsControl.ItemContainerStyle>
53+
<Style TargetType="ContentPresenter">
54+
<Setter Property="Margin" Value="0,8,0,8" />
55+
</Style>
56+
</ItemsControl.ItemContainerStyle>
57+
</ItemsControl>
58+
</ScrollViewer>
59+
</DataTemplate>
60+
</controls:GraphPresenter.ContentTemplate>
61+
</controls:GraphPresenter>
62+
</Grid>
63+
</Page>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Text.RegularExpressions;
6+
using CommunityToolkit.Authentication;
7+
using CommunityToolkit.Graph.Extensions;
8+
using Microsoft.Graph;
9+
using Windows.UI.Xaml.Controls;
10+
11+
namespace SampleTest.Samples.GraphPresenter
12+
{
13+
public sealed partial class MailMessagesSample : Page
14+
{
15+
public IBaseRequestBuilder MessagesRequestBuilder { get; set; }
16+
17+
public MailMessagesSample()
18+
{
19+
this.InitializeComponent();
20+
ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
21+
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
22+
}
23+
24+
private void OnProviderUpdated(object sender, IProvider provider)
25+
{
26+
if (provider == null)
27+
{
28+
ClearRequestBuilders();
29+
}
30+
}
31+
32+
private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
33+
{
34+
if (e.NewState == ProviderState.SignedIn)
35+
{
36+
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
37+
38+
MessagesRequestBuilder = graphClient.Me.Messages;
39+
}
40+
else
41+
{
42+
ClearRequestBuilders();
43+
}
44+
}
45+
46+
private void ClearRequestBuilders()
47+
{
48+
MessagesRequestBuilder = null;
49+
}
50+
51+
public static string RemoveWhitespace(string value)
52+
{
53+
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2654
54+
return Regex.Replace(value, @"\t|\r|\n", " ");
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)