using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
//--< Namespaces >--
//< UWP Windows 10 >
using Windows.Storage;
using Windows.System.UserProfile;
//</ UWP Windows 10 >
//--< Namespaces >--
namespace wpf_uwp_Set_Wallpaper
{
/// <summary>
/// Interaction logic for
MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
#region Region: Buttons
private async void btnSet_UWP_1_Click(object sender, RoutedEventArgs e)
{
await set_UWP_Wallpaper_Async("desktop_Background_01.jpg");
}
private async void btnSet_UWP_2_Click(object sender, RoutedEventArgs e)
{
await set_UWP_Wallpaper_Async("desktop_Background_02.jpg");
}
private void btnSet_WPF_2_Click(object sender, RoutedEventArgs e)
{
}
private void btnSet_WPF_1_Click(object sender, RoutedEventArgs e)
{
}
#endregion
async Task<bool> set_UWP_Wallpaper_Async(string sFilename)
{
//------------<
set_UWP_Wallpaper_Async() >------------
bool success = false;
if (UserProfilePersonalizationSettings.IsSupported())
{
//----< Profile Setting allowed
>----
string sFilename_with_Path = "C:\\_Daten\\Desktop\\Backgrounds\\" + sFilename ;
//< get File >
//*file under win32
//*using Windows.Storage
StorageFile file = await StorageFile.GetFileFromPathAsync(sFilename_with_Path);
//</ get File >
//< set profile >
UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
//</ set profile >
//< change Background >
success = await
profileSettings.TrySetWallpaperImageAsync(file);
//</ change Background >
MessageBox.Show(
DateTime.Now.ToString() + " file=" + file.Path + " success=" + success);
//----</ Profile Setting allowed
>----
//------------</
set_UWP_Wallpaper_Async() >------------
}
//< result >
return success;
//</ result >
//------------</ SetWallpaperAsync()
>------------
}
}
}
|