CommunityToolkit / Graph-Controls

Set of Helpers and Controls for Windows development using the Microsoft Graph.
https://docs.microsoft.com/en-us/windows/communitytoolkit/graph/overview
Other
155 stars 39 forks source link

Added GlobalProviderState to ProviderManager property for easy binding #117

Closed shweaver-MSFT closed 3 years ago

shweaver-MSFT commented 3 years ago

Fixes #

PR Type

What kind of change does this PR introduce?

What is the current behavior?

SwitchPresenter from WCT doesn't work well with the GlobalProvider state as it exists today. It is not possible to simply use ProviderManager.Instance.GlobalProvider.State because the GlobalProvider.State is only available after the provider has been set, so the initial binding fails and updates are never processed.

What is the new behavior?

Use the new GlobalProviderState getter to retrieve the current state of the active GlobalProvider, or null if none.

This is helpful for binding in XAML, since GlobalProviderState is consistently available via the ProviderManager.Instance singleton.

<controls:SwitchPresenter Value="{x:Bind auth:ProviderManager.Instance.GlobalProviderState, Mode=OneWay}">

    <controls:Case Value="{x:Bind auth:ProviderState.SignedIn}">
        <TextBlock Text="Signed in!" />
    </controls:Case>

    <controls:Case Value="{x:Bind auth:ProviderState.SignedOut}">
        <TextBlock Text="Signed out" />
    </controls:Case>

    <controls:Case Value="{x:Bind auth:ProviderState.Loading}">
        <TextBlock Text="Loading..." />
    </controls:Case>

    <controls:Case IsDefault="True">
        <TextBlock Text="No provider is set" />
    </controls:Case>
</controls:SwitchPresenter>

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

ghost commented 3 years ago

Thanks shweaver-MSFT for opening a Pull Request! The reviewers will test the PR and highlight if there is any merge conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌