-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1f01026
commit 3ca6264
Showing
17 changed files
with
725 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<Page | ||
x:Class="SampleTest.Samples.GraphPresenter.CalendarViewSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:SampleTest.Samples.GraphPresenter" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls" | ||
xmlns:global="using:System.Globalization" | ||
xmlns:graph="using:Microsoft.Graph" | ||
xmlns:samples="using:SampleTest.Samples" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<StackPanel> | ||
<TextBlock> | ||
The following example shows the `Me.CalendarView` API. | ||
</TextBlock> | ||
<TextBlock Margin="0,8,0,0" FontWeight="Bold"> | ||
My Upcoming Calendar Events: | ||
</TextBlock> | ||
</StackPanel> | ||
<controls:GraphPresenter | ||
Grid.Row="1" | ||
IsCollection="True" | ||
OrderBy="start/dateTime" | ||
RequestBuilder="{x:Bind CalendarViewRequestBuilder, Mode=OneWay}" | ||
ResponseType="graph:Event"> | ||
<controls:GraphPresenter.QueryOptions> | ||
<!-- Need to create separate Properties as multiple functions not supported in x:Bind see https://github.com/microsoft/microsoft-ui-xaml/issues/2407 --> | ||
<controls:QueryOption Name="startDateTime" Value="{x:Bind Today.ToString('o', global:CultureInfo.InvariantCulture)}" /> | ||
<controls:QueryOption Name="endDateTime" Value="{x:Bind ThreeDaysFromNow.ToString('o', global:CultureInfo.InvariantCulture)}" /> | ||
</controls:GraphPresenter.QueryOptions> | ||
<controls:GraphPresenter.ContentTemplate> | ||
<DataTemplate> | ||
<!-- Return result is a collection of Event's as we used 'IsCollection', so bind that first. --> | ||
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto"> | ||
<ItemsControl ItemsSource="{Binding}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate x:DataType="graph:Event"> | ||
<StackPanel> | ||
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{Binding Subject}" /> | ||
<TextBlock FontWeight="Bold"> | ||
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(Start), Mode=OneWay}" /> | ||
<Run>-</Run> | ||
<Run Text="{x:Bind samples:GraphPresenterSample.ToLocalTime(End), Mode=OneWay}" /> | ||
</TextBlock> | ||
<TextBlock> | ||
<Run FontFamily="Segoe MDL2 Assets" Text="" /> | ||
<Run /> | ||
<Run Text="{x:Bind Location.DisplayName, Mode=OneWay}" /> | ||
</TextBlock> | ||
</StackPanel> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
<ItemsControl.ItemContainerStyle> | ||
<Style TargetType="ContentPresenter"> | ||
<Setter Property="Margin" Value="0,8,0,8" /> | ||
</Style> | ||
</ItemsControl.ItemContainerStyle> | ||
</ItemsControl> | ||
</ScrollViewer> | ||
</DataTemplate> | ||
</controls:GraphPresenter.ContentTemplate> | ||
</controls:GraphPresenter> | ||
</Grid> | ||
</Page> |
59 changes: 59 additions & 0 deletions
59
SampleTest/Samples/GraphPresenter/CalendarViewSample.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using CommunityToolkit.Authentication; | ||
using CommunityToolkit.Graph.Extensions; | ||
using Microsoft.Graph; | ||
using Microsoft.Graph.Extensions; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace SampleTest.Samples.GraphPresenter | ||
{ | ||
public sealed partial class CalendarViewSample : Page | ||
{ | ||
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407 | ||
public DateTime Today => DateTimeOffset.Now.Date.ToUniversalTime(); | ||
|
||
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407 | ||
public DateTime ThreeDaysFromNow => Today.AddDays(3); | ||
|
||
public IBaseRequestBuilder CalendarViewRequestBuilder { get; set; } | ||
|
||
public CalendarViewSample() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
ProviderManager.Instance.ProviderUpdated += OnProviderUpdated; | ||
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged; | ||
} | ||
|
||
private void OnProviderUpdated(object sender, IProvider provider) | ||
{ | ||
if (provider == null) | ||
{ | ||
ClearRequestBuilders(); | ||
} | ||
} | ||
|
||
private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e) | ||
{ | ||
if (e.NewState == ProviderState.SignedIn) | ||
{ | ||
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient(); | ||
|
||
CalendarViewRequestBuilder = graphClient.Me.CalendarView; | ||
} | ||
else | ||
{ | ||
ClearRequestBuilders(); | ||
} | ||
} | ||
|
||
private void ClearRequestBuilders() | ||
{ | ||
CalendarViewRequestBuilder = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<Page | ||
x:Class="SampleTest.Samples.GraphPresenter.MailMessagesSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:SampleTest.Samples.GraphPresenter" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls" | ||
xmlns:graph="using:Microsoft.Graph" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<StackPanel> | ||
<TextBlock> | ||
The following example shows the `Me.Messages` API for getting a user's inbox mail messages. | ||
</TextBlock> | ||
<TextBlock Margin="0,8,0,0" FontWeight="Bold"> | ||
My Messages: | ||
</TextBlock> | ||
</StackPanel> | ||
<controls:GraphPresenter | ||
Grid.Row="1" | ||
IsCollection="True" | ||
RequestBuilder="{x:Bind MessagesRequestBuilder, Mode=OneWay}" | ||
ResponseType="graph:Message"> | ||
<controls:GraphPresenter.ContentTemplate> | ||
<DataTemplate> | ||
<ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto"> | ||
<ItemsControl ItemsSource="{Binding}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate x:DataType="graph:Message"> | ||
<StackPanel> | ||
<controls:PersonView | ||
Margin="-4" | ||
PersonQuery="{x:Bind Sender.EmailAddress.Address}" | ||
PersonViewType="OneLine" /> | ||
<TextBlock | ||
Padding="0" | ||
Style="{StaticResource BaseTextBlockStyle}" | ||
Text="{x:Bind Subject}" /> | ||
<TextBlock | ||
Text="{x:Bind local:MailMessagesSample.RemoveWhitespace(BodyPreview)}" | ||
TextWrapping="WrapWholeWords" /> | ||
</StackPanel> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
<ItemsControl.ItemContainerStyle> | ||
<Style TargetType="ContentPresenter"> | ||
<Setter Property="Margin" Value="0,8,0,8" /> | ||
</Style> | ||
</ItemsControl.ItemContainerStyle> | ||
</ItemsControl> | ||
</ScrollViewer> | ||
</DataTemplate> | ||
</controls:GraphPresenter.ContentTemplate> | ||
</controls:GraphPresenter> | ||
</Grid> | ||
</Page> |
57 changes: 57 additions & 0 deletions
57
SampleTest/Samples/GraphPresenter/MailMessagesSample.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Text.RegularExpressions; | ||
using CommunityToolkit.Authentication; | ||
using CommunityToolkit.Graph.Extensions; | ||
using Microsoft.Graph; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace SampleTest.Samples.GraphPresenter | ||
{ | ||
public sealed partial class MailMessagesSample : Page | ||
{ | ||
public IBaseRequestBuilder MessagesRequestBuilder { get; set; } | ||
|
||
public MailMessagesSample() | ||
{ | ||
this.InitializeComponent(); | ||
ProviderManager.Instance.ProviderUpdated += OnProviderUpdated; | ||
ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged; | ||
} | ||
|
||
private void OnProviderUpdated(object sender, IProvider provider) | ||
{ | ||
if (provider == null) | ||
{ | ||
ClearRequestBuilders(); | ||
} | ||
} | ||
|
||
private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e) | ||
{ | ||
if (e.NewState == ProviderState.SignedIn) | ||
{ | ||
var graphClient = ProviderManager.Instance.GlobalProvider.GetClient(); | ||
|
||
MessagesRequestBuilder = graphClient.Me.Messages; | ||
} | ||
else | ||
{ | ||
ClearRequestBuilders(); | ||
} | ||
} | ||
|
||
private void ClearRequestBuilders() | ||
{ | ||
MessagesRequestBuilder = null; | ||
} | ||
|
||
public static string RemoveWhitespace(string value) | ||
{ | ||
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2654 | ||
return Regex.Replace(value, @"\t|\r|\n", " "); | ||
} | ||
} | ||
} |
Oops, something went wrong.