C#, WPF, vb.Net, vba, SQL Server, Access Programmierer, Excel, ASP Core MVC Webforms Telefon: 07022/9319004 freib. Software Entwickler   Kontakt
#

WPF, Bridge: Fehler bei TrySetWallpaperImageAsync unter Win32

 

 

Unter Win32 (WPF/WinForms) stehen eine Liste an API Befehlen des Windows 10 zur Verfügung.

Damit kann man unter alten Windows Desktop Anwendungen langsam zum neuen Windows 10 UWP migrieren.

Unter Window 10 sind einige Zugriffe einfacher gelöst, aber andere Vorgänge sind leider nicht möglich oder erschwert.

 

 

Hier das Ändern des Desktop Hintergrundes (Wallpaper) unter Win32 mit einer Windows 10 API.

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() >------------

            }

 

 

Obwohl die Programmierung einfach ist und auch funktionieren sollte, erscheint das Ergebnis immer als false.

In der API Liste steht hierzu der Hinweis:

Nicht alle APIs werden derzeit für konvertierte Apps unterstützt.

Das heißt, man muss selber herausfinden, welche API nun geht oder nicht.

 

 

 

 

Die liste der angeblich möglichen Verwendungen von Windows 10 API unter Windows 32 ist unter:

Desktop to UWP Supported API

https://docs.microsoft.com/de-de/windows/uwp/porting/desktop-to-uwp-supported-api

 

und speziell für das Setzen des Desktop Hintergrund Bildes:

https://docs.microsoft.com/en-us/uwp/api/Windows.System.UserProfile.UserProfilePersonalizationSettings

UserProfilePersonalizationSettings Class

Namespace: Windows.System.UserProfile

Provides properties and methods to manage the user's desktop wallpaper and lock screen background image.

 

 

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() >------------

        }

 

       

    }

}

 

 

Mobile
»
WPF, Bridge: Fehler bei TrySetWallpaperImageAsync unter Win32
»
DAC Fehler: Base image BaseImage-15063.wim could not be found

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Raimund.Popp@Microsoft-Programmierer.de