From 3cc9cab04fc2a5e7b8a182c97e14d645e287a108 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 27 Sep 2024 18:31:14 -0700 Subject: [PATCH] Switch UWP XAML sample app to .NET 8 --- .../ComputeSharp.SwapChain.Uwp/App.xaml.cs | 110 +++-------- .../ComputeSharp.SwapChain.Uwp.csproj | 179 ++---------------- .../MainPage.xaml.cs | 30 +-- .../Properties/AssemblyInfo.cs | 27 --- .../Properties/Default.rd.xml | 31 --- .../PublishProfiles/win-arm64.pubxml | 11 ++ .../Properties/PublishProfiles/win-x64.pubxml | 11 ++ .../Properties/launchSettings.json | 7 + 8 files changed, 81 insertions(+), 325 deletions(-) delete mode 100644 samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs delete mode 100644 samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml create mode 100644 samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-arm64.pubxml create mode 100644 samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-x64.pubxml create mode 100644 samples/ComputeSharp.SwapChain.Uwp/Properties/launchSettings.json diff --git a/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs b/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs index f7fb87ab..77206708 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs +++ b/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs @@ -1,100 +1,46 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; -using Windows.Foundation; -using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; -namespace ComputeSharp.SwapChain.Uwp +namespace ComputeSharp.SwapChain.Uwp; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +sealed partial class App : Application { /// - /// Provides application-specific behavior to supplement the default Application class. + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). /// - sealed partial class App : Application + public App() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() + InitializeComponent(); + } + + /// + protected override void OnLaunched(LaunchActivatedEventArgs e) + { + // Initialize the frame if needed + if (Window.Current.Content is not Frame rootFrame) { - this.InitializeComponent(); - this.Suspending += OnSuspending; + // Create a Frame to act as the navigation context and navigate to the first page + rootFrame = new Frame(); + + // Place the frame in the current Window + Window.Current.Content = rootFrame; } - /// - /// Invoked when the application is launched normally by the end user. Other entry points - /// will be used such as when the application is launched to open a specific file. - /// - /// Details about the launch request and process. - protected override void OnLaunched(LaunchActivatedEventArgs e) + if (!e.PrelaunchActivated) { - Frame rootFrame = Window.Current.Content as Frame; - - // Do not repeat app initialization when the Window already has content, - // just ensure that the window is active - if (rootFrame == null) + if (rootFrame.Content is null) { - // Create a Frame to act as the navigation context and navigate to the first page - rootFrame = new Frame(); - - rootFrame.NavigationFailed += OnNavigationFailed; - - if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) - { - //TODO: Load state from previously suspended application - } - - // Place the frame in the current Window - Window.Current.Content = rootFrame; + // Navigate to the root page + _ = rootFrame.Navigate(typeof(MainPage), e.Arguments); } - if (e.PrelaunchActivated == false) - { - if (rootFrame.Content == null) - { - // When the navigation stack isn't restored navigate to the first page, - // configuring the new page by passing required information as a navigation - // parameter - rootFrame.Navigate(typeof(MainPage), e.Arguments); - } - // Ensure the current window is active - Window.Current.Activate(); - } - } - - /// - /// Invoked when Navigation to a certain page fails - /// - /// The Frame which failed navigation - /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) - { - throw new Exception("Failed to load Page " + e.SourcePageType.FullName); - } - - /// - /// Invoked when application execution is being suspended. Application state is saved - /// without knowing whether the application will be terminated or resumed with the contents - /// of memory still intact. - /// - /// The source of the suspend request. - /// Details about the suspend request. - private void OnSuspending(object sender, SuspendingEventArgs e) - { - var deferral = e.SuspendingOperation.GetDeferral(); - //TODO: Save application state and stop any background activity - deferral.Complete(); + // Ensure the current window is active + Window.Current.Activate(); } } } diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index c1ada231..055b7bb2 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -1,168 +1,23 @@ - - - + - Debug - x86 - {6A861D53-2DBD-4B4F-8543-90DC8C0F2DC8} - AppContainerExe - Properties - ComputeSharp.SwapChain.Uwp - ComputeSharp.SwapChain.Uwp - en-US - UAP - 10.0.26100.0 + WinExe + net8.0-windows10.0.26100.0 10.0.17763.0 - 14 - 512 - {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - true - false - - - true - bin\x86\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - x86 - false - prompt - true - - - bin\x86\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - x86 - false - prompt - true - true - - - true - bin\ARM\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - ARM - false - prompt - true - - - bin\ARM\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - ARM - false - prompt - true - true - - - true - bin\ARM64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - ARM64 - false - prompt - true - true - - - bin\ARM64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - ARM64 - false - prompt - true - true - - - true - bin\x64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - x64 - false - prompt - true - - - bin\x64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - x64 - false - prompt - true - true - - - PackageReference + 10.0.26100.45 + true + true + x86;x64;arm64 + win-x86;win-x64;win-arm64 + en-US + true + win-$(Platform).pubxml + true + - - App.xaml - - - MainPage.xaml - - + + + + - - - Designer - - - - - - - - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - 6.2.14 - - - - 14.0 - - - \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/MainPage.xaml.cs b/samples/ComputeSharp.SwapChain.Uwp/MainPage.xaml.cs index c9c203eb..8319d033 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/MainPage.xaml.cs +++ b/samples/ComputeSharp.SwapChain.Uwp/MainPage.xaml.cs @@ -1,30 +1,14 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; -// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 +namespace ComputeSharp.SwapChain.Uwp; -namespace ComputeSharp.SwapChain.Uwp +/// +/// An empty page that can be used on its own or navigated to within a Frame. +/// +public sealed partial class MainPage : Page { - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public sealed partial class MainPage : Page + public MainPage() { - public MainPage() - { - this.InitializeComponent(); - } + InitializeComponent(); } } diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs b/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs deleted file mode 100644 index b6fb87da..00000000 --- a/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ComputeSharp.SwapChain.Uwp")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ComputeSharp.SwapChain.Uwp")] -[assembly: AssemblyCopyright("Copyright © 2024")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: ComVisible(false)] diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml b/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml deleted file mode 100644 index af00722c..00000000 --- a/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-arm64.pubxml b/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-arm64.pubxml new file mode 100644 index 00000000..5de0b991 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-arm64.pubxml @@ -0,0 +1,11 @@ + + + + FileSystem + ARM64 + win-arm64 + bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true + true + + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-x64.pubxml b/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-x64.pubxml new file mode 100644 index 00000000..89844a87 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Properties/PublishProfiles/win-x64.pubxml @@ -0,0 +1,11 @@ + + + + FileSystem + x64 + win-x64 + bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true + true + + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/launchSettings.json b/samples/ComputeSharp.SwapChain.Uwp/Properties/launchSettings.json new file mode 100644 index 00000000..46264d2b --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "ComputeSharp.SwapChain.Uwp": { + "commandName": "MsixPackage" + } + } +} \ No newline at end of file