diff --git a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj index c849b9b..5b061cc 100644 --- a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj +++ b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj @@ -49,6 +49,10 @@ MSBuild:Compile + + + + $(DefineConstants);WINRT diff --git a/CommunityToolkit.Graph.Uwp/Triggers/ProviderStateTrigger.cs b/CommunityToolkit.Graph.Uwp/Triggers/ProviderStateTrigger.cs new file mode 100644 index 0000000..1a24f88 --- /dev/null +++ b/CommunityToolkit.Graph.Uwp/Triggers/ProviderStateTrigger.cs @@ -0,0 +1,77 @@ +// 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 CommunityToolkit.Authentication; +using Microsoft.Toolkit.Uwp; +using Microsoft.Toolkit.Uwp.Helpers; +using Windows.System; +using Windows.UI.Xaml; + +namespace CommunityToolkit.Graph.Uwp +{ + /// + /// A StateTrigger for detecting when the global authentication provider has been signed in. + /// + public class ProviderStateTrigger : StateTriggerBase + { + /// + /// Identifies the DependencyProperty. + /// + public static readonly DependencyProperty ActiveStateProperty = + DependencyProperty.Register(nameof(ActiveState), typeof(ProviderState), typeof(ProviderStateTrigger), new PropertyMetadata(null, OnStateChanged)); + + private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is ProviderStateTrigger instance) + { + instance.UpdateState(); + } + } + + private readonly DispatcherQueue _dispatcherQueue; + + /// + /// Gets or sets the expected ProviderState. + /// + public ProviderState? ActiveState + { + get => (ProviderState?)GetValue(ActiveStateProperty); + set => SetValue(ActiveStateProperty, value); + } + + /// + /// Initializes a new instance of the class. + /// + public ProviderStateTrigger() + { + _dispatcherQueue = DispatcherQueue.GetForCurrentThread(); + var weakEvent = + new WeakEventListener(this) + { + OnEventAction = (instance, source, args) => OnProviderUpdated(source, args), + OnDetachAction = (weakEventListener) => ProviderManager.Instance.ProviderUpdated -= weakEventListener.OnEvent, + }; + ProviderManager.Instance.ProviderUpdated += weakEvent.OnEvent; + UpdateState(); + } + + private void OnProviderUpdated(object sender, ProviderUpdatedEventArgs e) + { + _ = _dispatcherQueue.EnqueueAsync(UpdateState, DispatcherQueuePriority.Normal); + } + + private void UpdateState() + { + var provider = ProviderManager.Instance.GlobalProvider; + if (ActiveState != null && provider?.State != null) + { + SetActive(provider?.State == ActiveState); + } + else + { + SetActive(false); + } + } + } +} \ No newline at end of file diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index 817d2bf..54e9f68 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -7,302 +7,326 @@ xmlns:samples="using:SampleTest.Samples" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:CommunityToolkit.Graph.Uwp.Controls" - xmlns:toolkit="using:Microsoft.Toolkit" xmlns:global="using:System.Globalization" + xmlns:toolkit="using:Microsoft.Toolkit" + xmlns:global="using:System.Globalization" + xmlns:uwp="using:CommunityToolkit.Graph.Uwp" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The `LoginButton` above allows your user and application to easily connect to the Microsoft Graph. They can then also easily logout from the drop-down menu. + - - - - - - - - - The `LoginButton` above allows your user and application to easily connect to the Microsoft Graph. They can then also easily logout from the drop-down menu. - - - - - - - - - - The `PeoplePicker` lets a logged in user easily search for familiar people they interact with or contacts. Great for emails or messages. - - - - Picked People: - - - - - - - - - - - - - - - - - - The `GraphPresenter` is a unique control in the library which makes it easier for a developer to make any graph call and configure a nice display template in XAML. This opens up a world of possibilities for many uses outside of any other control available within this library. You can see a few examples of what's possible below. - - - - - - - - - - - - - The following example shows the `Me.CalendarView` API. - - My Upcoming Calendar Events: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following example shows the `Me.Messages` API for getting a user's inbox mail messages. - - My Messages: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following example shows the `Me.Planner.Tasks` API for getting a user's tasks. - - My Tasks: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Due - - - - - - - - - - - - - - - - - - - - - - - The following example shows the beta `Teams/id/Channels/id/messages` API for getting a list of messages (without replies) from a Channel in Teams. - - My Chat Messages: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + The `PeoplePicker` lets a logged in user easily search for familiar people they interact with or contacts. Great for emails or messages. + + + + Picked People: + + + + + + + + + + + + + + + + + + The `GraphPresenter` is a unique control in the library which makes it easier for a developer to make any graph call and configure a nice display template in XAML. This opens up a world of possibilities for many uses outside of any other control available within this library. You can see a few examples of what's possible below. + + + + + + + + + + + + + The following example shows the `Me.CalendarView` API. + + My Upcoming Calendar Events: + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + The following example shows the `Me.Messages` API for getting a user's inbox mail messages. + + My Messages: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The following example shows the `Me.Planner.Tasks` API for getting a user's tasks. + + My Tasks: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Due + + + + + + + + + + + + + + + + + + + + + + + The following example shows the beta `Teams/id/Channels/id/messages` API for getting a list of messages (without replies) from a Channel in Teams. + + My Chat Messages: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +