-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
466 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AppPinManager/AppPinManagerHelperCode.bind
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,20 @@ | ||
//Specific app pin to StartMenu | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinSpecificAppToStartMenuAsync(appList); | ||
|
||
//User Specific app in StartMenu | ||
var userInfo = await User.FindAllAsync(); | ||
if (userInfo.Count > 0) | ||
{ | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinUserSpecificAppToStartMenuAsync(userInfo[0], appList); | ||
} | ||
|
||
//Current app pin to TaskBar | ||
var pinResult = await AppPinManager.PinCurrentAppToTaskBarAsync(); | ||
|
||
|
||
//Specific app pin to TaskBar | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinSpecificAppToTaskBarAsync(appList); | ||
|
71 changes: 71 additions & 0 deletions
71
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AppPinManager/AppPinManagerHelperPage.xaml
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,71 @@ | ||
<Page | ||
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.AppPinManagerHelperPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" | ||
mc:Ignorable="d"> | ||
|
||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<Grid Background="{StaticResource Brush-Grey-05}"> | ||
|
||
<StackPanel VerticalAlignment="Top"> | ||
<StackPanel Margin="0 5 0 0"> | ||
<TextBlock Text="AppPinManager" Margin="5" FontSize="30"/> | ||
<StackPanel Margin="10"> | ||
<TextBlock Text="Pin to StartMenu" Margin="5" FontSize="20"/> | ||
|
||
<Button x:Name="SpecificAppSMenuButton" | ||
Margin="5" | ||
Click="SpecificAppSMenuButton_OnClick" | ||
Content="Pin Specific App To StartMenu" /> | ||
|
||
<Button x:Name="UserSpecificAppSMenuButton" | ||
Margin="5" | ||
Click="UserSpecificAppSMenuButton_OnClick" | ||
Content="Pin User Specific App To StartMenu" /> | ||
</StackPanel> | ||
<StackPanel Margin="10"> | ||
<TextBlock Text="Pin to TaskBar" Margin="5" FontSize="20"/> | ||
|
||
<Button x:Name="CurrentAppTBarButton" | ||
Margin="5" | ||
Click="CurrentAppTBarButton_OnClick" | ||
Content="Pin Current App To TaskBar" /> | ||
|
||
<Button x:Name="SpecificAppTBarButton" | ||
Margin="5" | ||
Click="SpecificAppTBarButton_OnClick" | ||
Content="Pin Specific App To TaskBar" /> | ||
</StackPanel> | ||
<StackPanel Margin="5" | ||
Orientation="Horizontal"> | ||
<TextBlock x:Name="StatusMessage" FontSize="25" /> | ||
</StackPanel> | ||
</StackPanel> | ||
</StackPanel> | ||
|
||
|
||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroup> | ||
<VisualState x:Name="Full"> | ||
<VisualState.StateTriggers> | ||
<AdaptiveTrigger MinWindowWidth="600" /> | ||
</VisualState.StateTriggers> | ||
</VisualState> | ||
<VisualState x:Name="Small"> | ||
<VisualState.StateTriggers> | ||
<AdaptiveTrigger MinWindowWidth="0" /> | ||
</VisualState.StateTriggers> | ||
|
||
<VisualState.Setters> | ||
<Setter Target="ButtonsPanel.Orientation" Value="Vertical" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateManager.VisualStateGroups> | ||
</Grid> | ||
</Grid> | ||
</Page> |
63 changes: 63 additions & 0 deletions
63
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AppPinManager/AppPinManagerHelperPage.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,63 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System; | ||
using Microsoft.Toolkit.Uwp.Helpers; | ||
using Windows.ApplicationModel; | ||
using Windows.System; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class AppPinManagerHelperPage : Page | ||
{ | ||
public AppPinManagerHelperPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private async void SpecificAppSMenuButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinSpecificAppToStartMenuAsync(appList); | ||
StatusMessage.Text = "SpecificApp in StartMenu : " + pinResult.ToString(); | ||
} | ||
|
||
private async void UserSpecificAppSMenuButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
var userInfo = await User.FindAllAsync(); | ||
if (userInfo.Count > 0) | ||
{ | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinUserSpecificAppToStartMenuAsync(userInfo[0], appList); | ||
StatusMessage.Text = "User SpecificApp in StartMenu : " + pinResult.ToString(); | ||
} | ||
} | ||
|
||
private async void CurrentAppTBarButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
var pinResult = await AppPinManager.PinCurrentAppToTaskBarAsync(); | ||
StatusMessage.Text = "Current App in TaskBar : " + pinResult.ToString(); | ||
} | ||
|
||
private async void SpecificAppTBarButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
var appList = (await Package.Current.GetAppListEntriesAsync())[0]; | ||
var pinResult = await AppPinManager.PinSpecificAppToTaskBarAsync(appList); | ||
StatusMessage.Text = "Specific App in TaskBar : " + pinResult.ToString(); | ||
} | ||
} | ||
} |
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
178 changes: 178 additions & 0 deletions
178
Microsoft.Toolkit.Uwp/Helpers/AppPinManager/AppPinManager.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,178 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Windows.ApplicationModel.Core; | ||
using Windows.Foundation.Metadata; | ||
using Windows.System; | ||
using Windows.UI.Shell; | ||
using Windows.UI.StartScreen; | ||
|
||
namespace Microsoft.Toolkit.Uwp.Helpers | ||
{ | ||
/// <summary> | ||
/// This class provides static helper methods help to add the app in startmenu or TaskBar. | ||
/// </summary> | ||
public static class AppPinManager | ||
{ | ||
/// <summary> | ||
/// Pin the current app in Windows TaskBar | ||
/// </summary> | ||
/// <returns>PinResult</returns> | ||
public static async Task<PinResult> PinCurrentAppToTaskBarAsync() | ||
{ | ||
var resultPinResult = PinResult.UnsupportedOs; | ||
|
||
if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager")) | ||
{ | ||
return resultPinResult; | ||
} | ||
|
||
if (TaskbarManager.GetDefault().IsSupported) | ||
{ | ||
if (TaskbarManager.GetDefault().IsPinningAllowed) | ||
{ | ||
if (await TaskbarManager.GetDefault().IsCurrentAppPinnedAsync()) | ||
{ | ||
resultPinResult = PinResult.PinAlreadyPresent; | ||
} | ||
else | ||
{ | ||
var result = await TaskbarManager.GetDefault().RequestPinCurrentAppAsync(); | ||
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.PinNotAllowed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.UnsupportedDevice; | ||
} | ||
|
||
return resultPinResult; | ||
} | ||
|
||
/// <summary> | ||
/// Pin Specific App in Windows TaskBar | ||
/// </summary> | ||
/// <param name="appListEntry">AppListEntry</param> | ||
/// <returns>PinResult</returns> | ||
public static async Task<PinResult> PinSpecificAppToTaskBarAsync(AppListEntry appListEntry) | ||
{ | ||
var resultPinResult = PinResult.UnsupportedOs; | ||
|
||
if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager")) | ||
{ | ||
return resultPinResult; | ||
} | ||
|
||
if (TaskbarManager.GetDefault().IsSupported) | ||
{ | ||
if (TaskbarManager.GetDefault().IsPinningAllowed) | ||
{ | ||
if (await TaskbarManager.GetDefault().IsAppListEntryPinnedAsync(appListEntry)) | ||
{ | ||
resultPinResult = PinResult.PinAlreadyPresent; | ||
} | ||
else | ||
{ | ||
var result = await TaskbarManager.GetDefault().RequestPinAppListEntryAsync(appListEntry); | ||
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.PinNotAllowed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.UnsupportedDevice; | ||
} | ||
|
||
return resultPinResult; | ||
} | ||
|
||
/// <summary> | ||
/// Pin Specific App in Windows StartMenu | ||
/// </summary> | ||
/// <param name="entry">AppListEntry</param> | ||
/// <returns>PinResult</returns> | ||
public static async Task<PinResult> PinSpecificAppToStartMenuAsync(AppListEntry entry) | ||
{ | ||
var resultPinResult = PinResult.UnsupportedOs; | ||
|
||
if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager")) | ||
{ | ||
return resultPinResult; | ||
} | ||
|
||
if (StartScreenManager.GetDefault().SupportsAppListEntry(entry)) | ||
{ | ||
if (await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry)) | ||
{ | ||
resultPinResult = PinResult.PinAlreadyPresent; | ||
} | ||
else | ||
{ | ||
var result = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry); | ||
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.UnsupportedDevice; | ||
} | ||
|
||
return resultPinResult; | ||
} | ||
|
||
/// <summary> | ||
/// Pin Specific App in Windows StartMenu based on User | ||
/// </summary> | ||
/// <param name="user">User</param> | ||
/// <param name="entry">AppListEntry</param> | ||
/// <returns>PinResult</returns> | ||
public static async Task<PinResult> PinUserSpecificAppToStartMenuAsync(User user, AppListEntry entry) | ||
{ | ||
var resultPinResult = PinResult.UnsupportedOs; | ||
|
||
if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager")) | ||
{ | ||
return resultPinResult; | ||
} | ||
|
||
if (StartScreenManager.GetForUser(user).SupportsAppListEntry(entry)) | ||
{ | ||
if (await StartScreenManager.GetForUser(user).ContainsAppListEntryAsync(entry)) | ||
{ | ||
resultPinResult = PinResult.PinAlreadyPresent; | ||
} | ||
else | ||
{ | ||
var result = await StartScreenManager.GetForUser(user).RequestAddAppListEntryAsync(entry); | ||
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed; | ||
} | ||
} | ||
else | ||
{ | ||
resultPinResult = PinResult.UnsupportedDevice; | ||
} | ||
|
||
return resultPinResult; | ||
} | ||
} | ||
} |
Oops, something went wrong.