From 20fe9f20f4ba0933d5b56dfc13a62be93a67566b Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Thu, 6 Jun 2024 14:12:55 +0200 Subject: [PATCH 1/2] [MRTCore] Add PrimaryLanguageOverride samples --- .../console_unpackaged_app.cpp | 13 +- .../PrimaryLanguageOverride/App.xaml | 16 +++ .../PrimaryLanguageOverride/App.xaml.cs | 86 ++++++++++++ .../Assets/LockScreenLogo.scale-200.png | Bin 0 -> 432 bytes .../Assets/SplashScreen.scale-200.png | Bin 0 -> 5372 bytes .../Assets/Square150x150Logo.scale-200.png | Bin 0 -> 1755 bytes .../Assets/Square44x44Logo.scale-200.png | Bin 0 -> 637 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 0 -> 283 bytes .../Assets/StoreLogo.png | Bin 0 -> 456 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 0 -> 2097 bytes .../PrimaryLanguageOverride/MainWindow.xaml | 15 +++ .../MainWindow.xaml.cs | 42 ++++++ .../PrimaryLanguageOverride.csproj | 51 +++++++ .../PrimaryLanguageOverride.sln | 43 ++++++ .../Strings/de-de/Resources.resw | 126 ++++++++++++++++++ .../Strings/en-us/Resources.resw | 126 ++++++++++++++++++ .../PrimaryLanguageOverride/app.manifest | 19 +++ 17 files changed, 535 insertions(+), 2 deletions(-) create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/LockScreenLogo.scale-200.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/SplashScreen.scale-200.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Square150x150Logo.scale-200.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Square44x44Logo.scale-200.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/StoreLogo.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Wide310x150Logo.scale-200.png create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml.cs create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.csproj create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.sln create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/de-de/Resources.resw create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/en-us/Resources.resw create mode 100644 Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/app.manifest diff --git a/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp b/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp index 47dec4185..8279c1ed6 100644 --- a/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp +++ b/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp @@ -27,9 +27,11 @@ int wmain(int argc, wchar_t* argv[]) " Default or default\n" " Override or override\n" " Fallback or fallback\n" + " PrimaryLanguageOverride or primarylanguageoverride\n" " Default and override retrieve a sample string from string resource files.\n" " For the override case, this sample uses the German language.\n" " Fallback corresponds to the resource-not-found case, where we fallback to a legacy resource loader.\n" + " PrimaryLanguageOverride uses ApplicationLanguages.PrimaryLanguageOverride property to override the language to German.\n" "\n" "Examples:\n" " Get the sample string for the default resource context\n" @@ -37,8 +39,10 @@ int wmain(int argc, wchar_t* argv[]) " Get the sample string for the override resource context (sample uses the German language for the override context)\n" " console_unpackaged_app.exe override\n" " Get the sample string for the resource-not-found fallback case\n" - " console_unpackaged_app.exe fallback\n"; - return 1; + " console_unpackaged_app.exe fallback\n" + " Get the sample string for the language overriden with ApplicationLanguages.PrimaryLanguageOverride (sample uses the German language)\n" + " console_unpackaged_app.exe primarylanguageoverride\n"; + return 1; } // Required for C++/WinRT. This call associates this thread with an apartment and initializes COM runtime. @@ -76,6 +80,11 @@ int wmain(int argc, wchar_t* argv[]) { std::wcout << manager.MainResourceMap().GetValue(L"Resources/LegacyString").ValueAsString().c_str() << std::endl; } + else if ((_wcsicmp(argv[1], L"PrimaryLanguageOverride") == 0) || (_wcsicmp(argv[1], L"primarylanguageoverride") == 0)) + { + ApplicationLanguages::PrimaryLanguageOverride(L"de-DE"); + std::wcout << manager.MainResourceMap().GetValue(L"Resources/SampleString").ValueAsString().c_str() << std::endl; + } else { std::wcout << "Invalid argument!" << std::endl; diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml new file mode 100644 index 000000000..1371d633a --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs new file mode 100644 index 000000000..2a811ad88 --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs @@ -0,0 +1,86 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Microsoft.UI.Xaml.Shapes; +using Microsoft.Windows.ApplicationModel.Resources; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Activation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace PrimaryLanguageOverride +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : Application + { + /// + /// 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() + { + // Set the primary language override to German (Germany) + // This will cause the app to use the German (Germany) resources + // Both resources loaded manually with ResourceLoader and XAML resources fetched with x:Uid will be in German (Germany) + ApplicationLanguages.PrimaryLanguageOverride = "de-DE"; + + this.InitializeComponent(); + } + + /// + /// Invoked when the application is launched. + /// + /// Details about the launch request and process. + protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) + { + m_resourceLoader = new ResourceLoader(); + + m_window = new MainWindow(m_resourceLoader); + m_window.Activate(); + + // Get the Window's HWND + var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(m_window); + + m_window.Title = "MRT Core PrimaryLanguageOverride sample"; + m_window.Activate(); + + // The Window object doesn't have Width and Height properties in WInUI 3 Desktop yet. + // To set the Width and Height, you can use the Win32 API SetWindowPos. + // Note, you should apply the DPI scale factor if you are thinking of DPI instead of pixels. + SetWindowSize(hwnd, 350, 300); + } + private void SetWindowSize(IntPtr hwnd, int width, int height) + { + var dpi = GetDpiForWindow(hwnd); + float scalingFactor = (float)dpi / 96; + width = (int)(width * scalingFactor); + height = (int)(height * scalingFactor); + + SetWindowPos(hwnd, System.IntPtr.Zero, 0, 0, width, height, 2); + } + + [DllImport("user32.dll", SetLastError = true)] + static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); + + [DllImport("user32.dll", SetLastError = true)] + static extern uint GetDpiForWindow(IntPtr hWnd); + + private ResourceLoader m_resourceLoader; + private Window m_window; + } +} diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/LockScreenLogo.scale-200.png b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..7440f0d4bf7c7e26e4e36328738c68e624ee851e GIT binary patch literal 432 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezr3(FqV6|IEGZ*x-#9g>~Mkr+x6^F zy~CDX2QIMs&Gcs3RnRBoxBA!*(Mfw0KTCYuYk0WlEIV>qBmPl! zq4ukrvfADX@#p8fbLY(H47N+k`FZ(FZh?cDro7>{8mkBO3>^oaIx`3!Jl)Qq)HI!+ z(S=1{o~eT)&W^=Ea8C`-17(Jv5(nHFJ{dOjGdxLVkY_y6&S1whfuFI4MM0kF0f&cO zPDVpV%nz;Id$>+0Ga5e9625-JcI)oq=#Pa3p^>8BB}21BUw@eN!-6@w%X+^`+Vn?! zryu|3T>kVWNBYyBc=7Y6H#s1Ah!OI_nezW zXTqOdkv2Az6KKBV=$yHdF^R3Fqw(TZEoNSZX>reXJ#bwX42%f|Pgg&ebxsLQ010xn AssI20 literal 0 HcmV?d00001 diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/SplashScreen.scale-200.png b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..32f486a86792a5e34cd9a8261b394c49b48f86be GIT binary patch literal 5372 zcmd5=Z){Ul6u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jgS+WdHyG literal 0 HcmV?d00001 diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Square44x44Logo.scale-200.png b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..f713bba67f551ef91020b75716a4dc8ebd744b1c GIT binary patch literal 637 zcmeAS@N?(olHy`uVBq!ia0vp^5g^RL1|$oo8kjIJFu8cTIEGZ*dUI*J;2{SImxtDO zm%3!R$UazoY}x{$j0P5ABYXWr(l=jxJ6ps1W{tV=^>{Dl><3nv3A}sm=EZ)#l3`NR zpZda3^rNox*D1%NC98Z~L*6zipLw~Gxn&(Y-;KmJ+aR6eLabU-L#y8HW%7P-E_-VlLqIabbHPHKT*)fT@9iWJ7iWgOT9%0}Lrj>lztPxWq6sPw3pi z#-<=#$jjrP_DD*i!RLsn0mIA=>4~N)IMYWIf=j%-zuKCdMG%tHYot70D1| zvWa0wMhauW#S>1CnI_;>!1Q3zMA17@DOVq{MQ+{U7^a&yA+%dMCG;WNPV0i;w$tu; zX^b}UKziPM)(<;)ruW;-`)bBN+rQNM*Zs_>?n$|FVFo-e*PZb*@U7VAd+tHb4e?=Blc~}S6K)wL}r*Gf`BM#QB z+y>N$mCswb4d{^{S9v_!eQj4fTRMOwOCi?lSk9%<=vAz}jM-*PQtH@Odn1LZcd^j#o> hW$4xn+CT+ep9lJ{OAO?njobhL002ovPDHLkV1nYebbkN< literal 0 HcmV?d00001 diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/StoreLogo.png b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Assets/StoreLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..a4586f26bdf7841cad10f39cdffe2aca3af252c1 GIT binary patch literal 456 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2o;fF!p=8IEGZ*dUM0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In18$w8yb=rmEmHxVEUA^?RwnB?6Qlp1os8@*dWTGL2bhzZ!s*xqScR?EPL` zo(JwNdKUUYy7GtvZ3asXm)cgFvCx9EmAi;|w=a0iGiv%%VYKh`P0Wma4y`Xyx|T~( zAmfGbgbEEC7)j8b@WA@+5W3a61HJXC1dX@6_T|Czk0I0zBk%tnW~()VWITGI!`$c< gARL?UBrYYkwoDw4eo*CrzXGTrZ@;GF>596)00d&n@&Et; literal 0 HcmV?d00001 diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml new file mode 100644 index 000000000..4543b96e6 --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml.cs b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml.cs new file mode 100644 index 000000000..b5a60b32f --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/MainWindow.xaml.cs @@ -0,0 +1,42 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Microsoft.Windows.ApplicationModel.Resources; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace PrimaryLanguageOverride +{ + /// + /// An empty window that can be used on its own or navigated to within a Frame. + /// + public sealed partial class MainWindow : Window + { + public MainWindow(ResourceLoader resourceLoader) + { + m_resourceLoader = resourceLoader; + + this.InitializeComponent(); + } + + private void SampleButton_Click(object sender, RoutedEventArgs e) + { + var resourceString = m_resourceLoader.GetString("SampleString"); + output.Text = resourceString; + } + + private ResourceLoader m_resourceLoader; + } +} diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.csproj b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.csproj new file mode 100644 index 000000000..7f6a5755d --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.csproj @@ -0,0 +1,51 @@ + + + WinExe + net8.0-windows10.0.19041.0 + 10.0.17763.0 + PrimaryLanguageOverride + app.manifest + x86;x64;ARM64 + win-x86;win-x64;win-arm64 + win10-x86;win10-x64;win10-arm64 + win-$(Platform).pubxml + true + true + 10.0.19041.35-preview + None + + + + + + + + + + + + + + + + + + + + + + + + + + true + + \ No newline at end of file diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.sln b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.sln new file mode 100644 index 000000000..688da24eb --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/PrimaryLanguageOverride.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimaryLanguageOverride", "PrimaryLanguageOverride.csproj", "{A7EE0A53-508D-4350-A184-A08F82DE050E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|ARM64.Build.0 = Debug|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x64.ActiveCfg = Debug|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x64.Build.0 = Debug|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x64.Deploy.0 = Debug|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x86.ActiveCfg = Debug|x86 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x86.Build.0 = Debug|x86 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Debug|x86.Deploy.0 = Debug|x86 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|ARM64.ActiveCfg = Release|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|ARM64.Build.0 = Release|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|ARM64.Deploy.0 = Release|ARM64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x64.ActiveCfg = Release|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x64.Build.0 = Release|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x64.Deploy.0 = Release|x64 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x86.ActiveCfg = Release|x86 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x86.Build.0 = Release|x86 + {A7EE0A53-508D-4350-A184-A08F82DE050E}.Release|x86.Deploy.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {98D0CE59-33E6-43A6-BC91-9333B95F7057} + EndGlobalSection +EndGlobal diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/de-de/Resources.resw b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/de-de/Resources.resw new file mode 100644 index 000000000..b7a671d70 --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/de-de/Resources.resw @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Deutscher Buttontext + + + Deutscher Text + + \ No newline at end of file diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/en-us/Resources.resw b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/en-us/Resources.resw new file mode 100644 index 000000000..578859317 --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/Strings/en-us/Resources.resw @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + English Button Text + + + English Text + + \ No newline at end of file diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/app.manifest b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/app.manifest new file mode 100644 index 000000000..5a81b08c0 --- /dev/null +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/app.manifest @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + PerMonitorV2 + + + \ No newline at end of file From bdb671340155f4b8f3415185acd92c4878e3944d Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Thu, 27 Jun 2024 15:14:02 +0200 Subject: [PATCH 2/2] Adjust namespace change as per implementation change --- .../cpp/cpp-console-unpackaged/console_unpackaged_app.cpp | 2 ++ .../cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp b/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp index 8279c1ed6..6515684ef 100644 --- a/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp +++ b/Samples/ResourceManagement/cpp/cpp-console-unpackaged/console_unpackaged_app.cpp @@ -8,11 +8,13 @@ #include "winrt\Windows.Foundation.h" #include "winrt\Windows.Foundation.Collections.h" #include "winrt\Microsoft.Windows.ApplicationModel.Resources.h" +#include "winrt\Microsoft.Windows.Globalization.h" #include using namespace winrt; using namespace winrt::Microsoft::Windows::ApplicationModel::Resources; +using namespace winrt::Microsoft::Windows::Globalization; int wmain(int argc, wchar_t* argv[]) { diff --git a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs index 2a811ad88..dc272f60c 100644 --- a/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs +++ b/Samples/ResourceManagement/cs/cs-winui-unpackaged/PrimaryLanguageOverride/App.xaml.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Navigation; using Microsoft.UI.Xaml.Shapes; using Microsoft.Windows.ApplicationModel.Resources; +using Microsoft.Windows.Globalization; using System; using System.Collections.Generic; using System.IO;