Hi, @Moying. Welcome to Microsoft Q&A.
Refer to the following method:
1.Create a WPF Application project (assuming you are creating a .net 8 version).
2.Refer to the documentation, open your csproj
file, and modify the TargetFramework
according to your target operating system. (Here, it is assumed that your target operating system is Windows 11, version 24H2
)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
3.Rebuild your project via Rebuild
4.Edit the code in MainWindow.xaml.cs
to set the lock screen picture.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += Window_Loaded;
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
string FilePath = @"The image you want to set";
Windows.Storage.StorageFile imageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(FilePath);
await Windows.System.UserProfile.LockScreen.SetImageFileAsync(imageFile);
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.