Skip to content

Commit 8e45dca

Browse files
jaigakPhonerApp
andauthored
Add option to set an image as lockscreen background (#755)
Co-authored-by: PhonerApp <63700223+PhonerApp@users.noreply.github.com>
1 parent 7222bfb commit 8e45dca

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

Files/Interacts/Interaction.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ public async void SetAsDesktopBackgroundItem_Click(object sender, RoutedEventArg
7575
await profileSettings.TrySetWallpaperImageAsync(file);
7676
}
7777

78+
public async void SetAsLockscreenBackgroundItem_Click(object sender, RoutedEventArgs e)
79+
{
80+
// Get the path of the selected file
81+
StorageFile sourceFile = await StorageFile.GetFileFromPathAsync((CurrentInstance.ContentPage as BaseLayout).SelectedItem.ItemPath);
82+
83+
// Get the app's local folder to use as the destination folder.
84+
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
85+
86+
// Copy the file to the destination folder.
87+
// Replace the existing file if the file already exists.
88+
StorageFile file = await sourceFile.CopyAsync(localFolder, "Background.png", NameCollisionOption.ReplaceExisting);
89+
90+
// Set the lockscreen background
91+
await LockScreen.SetImageFileAsync(file);
92+
}
93+
7894
public void OpenNewTab()
7995
{
8096
instanceTabsView.AddNewTab(typeof(ModernShellPage), "New tab");

Files/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,7 @@
585585
<data name="ItemAlreadyExistsDialogTitle" xml:space="preserve">
586586
<value>Item already exists</value>
587587
</data>
588+
<data name="BaseLayoutItemContextFlyoutSetAsLockscreenBackground" xml:space="preserve">
589+
<value>Set as lockscreen background</value>
590+
</data>
588591
</root>

Files/UserControls/LayoutModes/GenericFileBrowser.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@
192192
<FontIcon Glyph="&#xE7F4;" />
193193
</MenuFlyoutItem.Icon>
194194
</MenuFlyoutItem>
195+
<MenuFlyoutItem
196+
x:Name="SetAsLockscreenBackgroundItem"
197+
x:Uid="BaseLayoutItemContextFlyoutSetAsLockscreenBackground"
198+
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsLockscreenBackgroundItem_Click}"
199+
Text="Set as lockscreen background"
200+
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
201+
<MenuFlyoutItem.Icon>
202+
<FontIcon Glyph="&#xEE3F;" />
203+
</MenuFlyoutItem.Icon>
204+
</MenuFlyoutItem>
195205
<MenuFlyoutItem
196206
x:Name="ShareItem"
197207
x:Uid="BaseLayoutItemContextFlyoutShare"

Files/UserControls/LayoutModes/PhotoAlbum.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,17 @@
188188
</MenuFlyoutItem.Icon>
189189
</MenuFlyoutItem>
190190
<MenuFlyoutItem
191-
x:Name="ShareItem"
191+
x:Name="SetAsLockscreenBackgroundItem"
192+
x:Uid="BaseLayoutItemContextFlyoutSetAsLockscreenBackground"
193+
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsLockscreenBackgroundItem_Click}"
194+
Text="Set as lockscreen background"
195+
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
196+
<MenuFlyoutItem.Icon>
197+
<FontIcon Glyph="&#xEE3F;" />
198+
</MenuFlyoutItem.Icon>
199+
</MenuFlyoutItem>
200+
<MenuFlyoutItem
201+
x:Name="ShareItem"
192202
x:Uid="BaseLayoutItemContextFlyoutShare"
193203
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.ShareItem_Click}"
194204
Text="Share">

0 commit comments

Comments
 (0)