diff --git a/Samples/Islands/DrawingIsland/App.config b/Samples/Islands/DrawingIsland/App.config new file mode 100644 index 000000000..51fffc74b --- /dev/null +++ b/Samples/Islands/DrawingIsland/App.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/App.cs b/Samples/Islands/DrawingIsland/App.cs new file mode 100644 index 000000000..88b464d27 --- /dev/null +++ b/Samples/Islands/DrawingIsland/App.cs @@ -0,0 +1,29 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows; +using Microsoft.UI.Dispatching; + +namespace CalculatorDemo +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + _dispacherQueueController = DispatcherQueueController.CreateOnCurrentThread(); + base.OnStartup(e); + } + + protected override void OnExit(ExitEventArgs e) + { + base.OnExit(e); + _dispacherQueueController?.ShutdownQueue(); + _dispacherQueueController = null; + } + + DispatcherQueueController? _dispacherQueueController; + } +} \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/App.xaml b/Samples/Islands/DrawingIsland/App.xaml new file mode 100644 index 000000000..7f1cb151f --- /dev/null +++ b/Samples/Islands/DrawingIsland/App.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/CalculatorDemo.csproj b/Samples/Islands/DrawingIsland/CalculatorDemo.csproj new file mode 100644 index 000000000..5de1a2517 --- /dev/null +++ b/Samples/Islands/DrawingIsland/CalculatorDemo.csproj @@ -0,0 +1,107 @@ + + + + net9.0-windows10.0.22621.0 + true + false + win-x64;win-x86;win-arm64 + x64;x86;ARM64 + false + false + + + Debug + AnyCPU + {5731865D-6685-47A7-8877-5DBAF39B54CD} + WinExe + Properties + CalculatorDemo + CalculatorDemo + 512 + 4 + true + + + AnyCPU + true + portable + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/Islands/DrawingIsland/CalculatorDemo.sln b/Samples/Islands/DrawingIsland/CalculatorDemo.sln new file mode 100644 index 000000000..83f8f2b7a --- /dev/null +++ b/Samples/Islands/DrawingIsland/CalculatorDemo.sln @@ -0,0 +1,71 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34825.169 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalculatorDemo", "CalculatorDemo.csproj", "{5731865D-6685-47A7-8877-5DBAF39B54CD}" +EndProject +Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CalculatorDemoPackage", "CalculatorDemoPackage\CalculatorDemoPackage.wapproj", "{B100DA96-7F60-4053-9E91-554AFB2B3DB2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawingIslandCsProjection", "..\..\..\..\WindowsAppSDK-Samples\Samples\Islands\DrawingIsland\DrawingIslandCsProjection\DrawingIslandCsProjection.csproj", "{91B33F67-B850-4407-A85D-51A4A229DF10}" +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 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|ARM64.Build.0 = Debug|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x64.ActiveCfg = Debug|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x64.Build.0 = Debug|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x86.ActiveCfg = Debug|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x86.Build.0 = Debug|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|ARM64.ActiveCfg = Release|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|ARM64.Build.0 = Release|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x64.ActiveCfg = Release|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x64.Build.0 = Release|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x86.ActiveCfg = Release|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x86.Build.0 = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.Build.0 = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.ActiveCfg = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.Build.0 = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.Deploy.0 = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.ActiveCfg = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.Build.0 = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.Deploy.0 = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.ActiveCfg = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.Build.0 = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.Deploy.0 = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.ActiveCfg = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.Build.0 = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.Deploy.0 = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.ActiveCfg = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.Build.0 = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.Deploy.0 = Release|x86 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|ARM64.Build.0 = Debug|ARM64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|x64.ActiveCfg = Debug|x64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|x64.Build.0 = Debug|x64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|x86.ActiveCfg = Debug|x86 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Debug|x86.Build.0 = Debug|x86 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|ARM64.ActiveCfg = Release|ARM64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|ARM64.Build.0 = Release|ARM64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|x64.ActiveCfg = Release|x64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|x64.Build.0 = Release|x64 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|x86.ActiveCfg = Release|x86 + {91B33F67-B850-4407-A85D-51A4A229DF10}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BD33D0CF-3B40-4BE8-8A0E-FC7948B82266} + EndGlobalSection +EndGlobal diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/CalculatorDemoPackage.wapproj b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/CalculatorDemoPackage.wapproj new file mode 100644 index 000000000..de96ab37e --- /dev/null +++ b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/CalculatorDemoPackage.wapproj @@ -0,0 +1,74 @@ + + + + 15.0 + + + + Debug + x86 + + + Release + x86 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + $(MSBuildExtensionsPath)\Microsoft\DesktopBridge\ + + + + b100da96-7f60-4053-9e91-554afb2b3db2 + 10.0.22621.0 + 10.0.17763.0 + en-US + false + $(NoWarn);NU1702 + ..\CalculatorDemo.csproj + Windows + .NETCoreApp,Version=v9.0 + net9.0-windows10.0.17763.0 + win-x64;win-x86;win-arm64 + x64;x86;ARM64 + false + false + + + + Designer + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/LockScreenLogo.scale-200.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/LockScreenLogo.scale-200.png new file mode 100644 index 000000000..735f57adb Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/LockScreenLogo.scale-200.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/SplashScreen.scale-200.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/SplashScreen.scale-200.png new file mode 100644 index 000000000..023e7f1fe Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/SplashScreen.scale-200.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square150x150Logo.scale-200.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square150x150Logo.scale-200.png new file mode 100644 index 000000000..af49fec1a Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square150x150Logo.scale-200.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.scale-200.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.scale-200.png new file mode 100644 index 000000000..ce342a2ec Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.scale-200.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 000000000..f6c02ce97 Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/StoreLogo.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/StoreLogo.png new file mode 100644 index 000000000..7385b56c0 Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/StoreLogo.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Wide310x150Logo.scale-200.png b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Wide310x150Logo.scale-200.png new file mode 100644 index 000000000..288995b39 Binary files /dev/null and b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Images/Wide310x150Logo.scale-200.png differ diff --git a/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Package.appxmanifest b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Package.appxmanifest new file mode 100644 index 000000000..a8fc2737e --- /dev/null +++ b/Samples/Islands/DrawingIsland/CalculatorDemoPackage/Package.appxmanifest @@ -0,0 +1,49 @@ + + + + + + + + CalculatorDemoPackage + jecollin + Images\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/Islands/DrawingIsland/DrawingCsTestApp/DrawingCsTestApp.csproj b/Samples/Islands/DrawingIsland/DrawingCsTestApp/DrawingCsTestApp.csproj index 6128a7e47..7a231196f 100644 --- a/Samples/Islands/DrawingIsland/DrawingCsTestApp/DrawingCsTestApp.csproj +++ b/Samples/Islands/DrawingIsland/DrawingCsTestApp/DrawingCsTestApp.csproj @@ -4,7 +4,7 @@ WinExe - net8.0-windows10.0.22621.0 + net9.0-windows10.0.22621.0 enable enable x64;ARM64;x86 diff --git a/Samples/Islands/DrawingIsland/DrawingCsTestPackage/DrawingCsTestPackage.wapproj b/Samples/Islands/DrawingIsland/DrawingCsTestPackage/DrawingCsTestPackage.wapproj index 5d130fa8d..9ea5b74a9 100644 --- a/Samples/Islands/DrawingIsland/DrawingCsTestPackage/DrawingCsTestPackage.wapproj +++ b/Samples/Islands/DrawingIsland/DrawingCsTestPackage/DrawingCsTestPackage.wapproj @@ -41,6 +41,14 @@ false $(NoWarn);NU1702 ..\DrawingCsTestApp\DrawingCsTestApp.csproj + Windows + .NETCoreApp,Version=v9.0 + net9.0-windows10.0.22621.0 + win-x64;win-x86;win-arm64 + x64;x86;ARM64 + true + false + false diff --git a/Samples/Islands/DrawingIsland/DrawingIsland.sln b/Samples/Islands/DrawingIsland/DrawingIsland.sln index 74fb743d9..ed6805296 100644 --- a/Samples/Islands/DrawingIsland/DrawingIsland.sln +++ b/Samples/Islands/DrawingIsland/DrawingIsland.sln @@ -13,7 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawingCsTestApp", "Drawing EndProject Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "DrawingCsTestPackage", "DrawingCsTestPackage\DrawingCsTestPackage.wapproj", "{3ED80AF8-0D53-4568-8A9A-BCB852B85DC7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawingIslandCsProjection", "DrawingIslandCsProjection\DrawingIslandCsProjection.csproj", "{48847923-880A-4A61-99CF-64B8EABD412B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawingIslandCsProjection", "DrawingIslandCsProjection\DrawingIslandCsProjection.csproj", "{48847923-880A-4A61-99CF-64B8EABD412B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalculatorDemo", "CalculatorDemo.csproj", "{5731865D-6685-47A7-8877-5DBAF39B54CD}" +EndProject +Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CalculatorDemoPackage", "CalculatorDemoPackage\CalculatorDemoPackage.wapproj", "{B100DA96-7F60-4053-9E91-554AFB2B3DB2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -109,6 +113,36 @@ Global {48847923-880A-4A61-99CF-64B8EABD412B}.Release|x64.Build.0 = Release|x64 {48847923-880A-4A61-99CF-64B8EABD412B}.Release|x86.ActiveCfg = Release|x86 {48847923-880A-4A61-99CF-64B8EABD412B}.Release|x86.Build.0 = Release|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|ARM64.Build.0 = Debug|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x64.ActiveCfg = Debug|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x64.Build.0 = Debug|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x86.ActiveCfg = Debug|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Debug|x86.Build.0 = Debug|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|ARM64.ActiveCfg = Release|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|ARM64.Build.0 = Release|ARM64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x64.ActiveCfg = Release|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x64.Build.0 = Release|x64 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x86.ActiveCfg = Release|x86 + {5731865D-6685-47A7-8877-5DBAF39B54CD}.Release|x86.Build.0 = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.Build.0 = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.ActiveCfg = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.Build.0 = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x64.Deploy.0 = Debug|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.ActiveCfg = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.Build.0 = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Debug|x86.Deploy.0 = Debug|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.ActiveCfg = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.Build.0 = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|ARM64.Deploy.0 = Release|ARM64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.ActiveCfg = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.Build.0 = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x64.Deploy.0 = Release|x64 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.ActiveCfg = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.Build.0 = Release|x86 + {B100DA96-7F60-4053-9E91-554AFB2B3DB2}.Release|x86.Deploy.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Samples/Islands/DrawingIsland/DrawingIslandCsProjection/DrawingIslandCsProjection.csproj b/Samples/Islands/DrawingIsland/DrawingIslandCsProjection/DrawingIslandCsProjection.csproj index 149d98603..47f2763a6 100644 --- a/Samples/Islands/DrawingIsland/DrawingIslandCsProjection/DrawingIslandCsProjection.csproj +++ b/Samples/Islands/DrawingIsland/DrawingIslandCsProjection/DrawingIslandCsProjection.csproj @@ -2,7 +2,7 @@ - net8.0-windows10.0.22621.0 + net9.0-windows10.0.22621.0 enable enable x64;x86;ARM64 diff --git a/Samples/Islands/DrawingIsland/MainWindow.cs b/Samples/Islands/DrawingIsland/MainWindow.cs new file mode 100644 index 000000000..4ebb4cf52 --- /dev/null +++ b/Samples/Islands/DrawingIsland/MainWindow.cs @@ -0,0 +1,455 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace CalculatorDemo +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public sealed partial class MainWindow : Window + { + private static PaperTrail _paper; + private Operation _lastOper; + private string _lastVal; + private string _memVal; + + public MainWindow() + { + InitializeComponent(); + _paper = new PaperTrail(this); + ProcessKey('0'); + EraseDisplay = true; + } + + /// + /// Flag to erase or just add to current display flag + /// + private bool EraseDisplay { get; set; } + + /// + /// Get/Set Memory cell value + /// + private double Memory + { + get + { + if (_memVal == string.Empty) + return 0.0; + return Convert.ToDouble(_memVal); + } + set { _memVal = value.ToString(CultureInfo.InvariantCulture); } + } + + //Lats value entered + private string LastValue + { + get + { + if (_lastVal == string.Empty) + return "0"; + return _lastVal; + } + set { _lastVal = value; } + } + + //The current Calculator display + private string Display { get; set; } + // Sample event handler: + private void OnWindowKeyDown(object sender, TextCompositionEventArgs /*System.Windows.Input.KeyEventArgs*/ e) + { + var s = e.Text; + var c = (s.ToCharArray())[0]; + e.Handled = true; + + if ((c >= '0' && c <= '9') || c == '.' || c == '\b') // '\b' is backspace + { + ProcessKey(c); + return; + } + switch (c) + { + case '+': + ProcessOperation("BPlus"); + break; + case '-': + ProcessOperation("BMinus"); + break; + case '*': + ProcessOperation("BMultiply"); + break; + case '/': + ProcessOperation("BDevide"); + break; + case '%': + ProcessOperation("BPercent"); + break; + case '=': + ProcessOperation("BEqual"); + break; + } + } + + private void DigitBtn_Click(object sender, RoutedEventArgs e) + { + var s = ((Button) sender).Content.ToString(); + + //char[] ids = ((Button)sender).ID.ToCharArray(); + var ids = s.ToCharArray(); + ProcessKey(ids[0]); + } + + private void ProcessKey(char c) + { + if (EraseDisplay) + { + Display = string.Empty; + EraseDisplay = false; + } + AddToDisplay(c); + } + + private void ProcessOperation(string s) + { + var d = 0.0; + switch (s) + { + case "BPM": + _lastOper = Operation.Negate; + LastValue = Display; + CalcResults(); + LastValue = Display; + EraseDisplay = true; + _lastOper = Operation.None; + break; + case "BDevide": + + if (EraseDisplay) //stil wait for a digit... + { + //stil wait for a digit... + _lastOper = Operation.Devide; + break; + } + CalcResults(); + _lastOper = Operation.Devide; + LastValue = Display; + EraseDisplay = true; + break; + case "BMultiply": + if (EraseDisplay) //stil wait for a digit... + { + //stil wait for a digit... + _lastOper = Operation.Multiply; + break; + } + CalcResults(); + _lastOper = Operation.Multiply; + LastValue = Display; + EraseDisplay = true; + break; + case "BMinus": + if (EraseDisplay) //stil wait for a digit... + { + //stil wait for a digit... + _lastOper = Operation.Subtract; + break; + } + CalcResults(); + _lastOper = Operation.Subtract; + LastValue = Display; + EraseDisplay = true; + break; + case "BPlus": + if (EraseDisplay) + { + //stil wait for a digit... + _lastOper = Operation.Add; + break; + } + CalcResults(); + _lastOper = Operation.Add; + LastValue = Display; + EraseDisplay = true; + break; + case "BEqual": + if (EraseDisplay) //stil wait for a digit... + break; + CalcResults(); + EraseDisplay = true; + _lastOper = Operation.None; + LastValue = Display; + //val = Display; + break; + case "BSqrt": + _lastOper = Operation.Sqrt; + LastValue = Display; + CalcResults(); + LastValue = Display; + EraseDisplay = true; + _lastOper = Operation.None; + break; + case "BPercent": + if (EraseDisplay) //stil wait for a digit... + { + //stil wait for a digit... + _lastOper = Operation.Percent; + break; + } + CalcResults(); + _lastOper = Operation.Percent; + LastValue = Display; + EraseDisplay = true; + //LastOper = Operation.None; + break; + case "BOneOver": + _lastOper = Operation.OneX; + LastValue = Display; + CalcResults(); + LastValue = Display; + EraseDisplay = true; + _lastOper = Operation.None; + break; + case "BC": //clear All + _lastOper = Operation.None; + Display = LastValue = string.Empty; + _paper.Clear(); + UpdateDisplay(); + break; + case "BCE": //clear entry + _lastOper = Operation.None; + Display = LastValue; + UpdateDisplay(); + break; + case "BMemClear": + Memory = 0.0F; + DisplayMemory(); + break; + case "BMemSave": + Memory = Convert.ToDouble(Display); + DisplayMemory(); + EraseDisplay = true; + break; + case "BMemRecall": + Display = /*val =*/ Memory.ToString(CultureInfo.InvariantCulture); + UpdateDisplay(); + //if (LastOper != Operation.None) //using MR is like entring a digit + EraseDisplay = false; + break; + case "BMemPlus": + d = Memory + Convert.ToDouble(Display); + Memory = d; + DisplayMemory(); + EraseDisplay = true; + break; + } + } + + private void OperBtn_Click(object sender, RoutedEventArgs e) + { + ProcessOperation(((Button) sender).Name); + } + + private double Calc(Operation lastOper) + { + var d = 0.0; + + + try + { + switch (lastOper) + { + case Operation.Devide: + _paper.AddArguments(LastValue + " / " + Display); + d = (Convert.ToDouble(LastValue)/Convert.ToDouble(Display)); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Add: + _paper.AddArguments(LastValue + " + " + Display); + d = Convert.ToDouble(LastValue) + Convert.ToDouble(Display); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Multiply: + _paper.AddArguments(LastValue + " * " + Display); + d = Convert.ToDouble(LastValue)*Convert.ToDouble(Display); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Percent: + //Note: this is different (but make more sense) then Windows calculator + _paper.AddArguments(LastValue + " % " + Display); + d = (Convert.ToDouble(LastValue)*Convert.ToDouble(Display))/100.0F; + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Subtract: + _paper.AddArguments(LastValue + " - " + Display); + d = Convert.ToDouble(LastValue) - Convert.ToDouble(Display); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Sqrt: + _paper.AddArguments("Sqrt( " + LastValue + " )"); + d = Math.Sqrt(Convert.ToDouble(LastValue)); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.OneX: + _paper.AddArguments("1 / " + LastValue); + d = 1.0F/Convert.ToDouble(LastValue); + CheckResult(d); + _paper.AddResult(d.ToString(CultureInfo.InvariantCulture)); + break; + case Operation.Negate: + d = Convert.ToDouble(LastValue)*(-1.0F); + break; + } + } + catch + { + d = 0; + var parent = (Window) MyPanel.Parent; + _paper.AddResult("Error"); + MessageBox.Show(parent, "Operation cannot be perfomed", parent.Title); + } + + return d; + } + + private void CheckResult(double d) + { + if (double.IsNegativeInfinity(d) || double.IsPositiveInfinity(d) || double.IsNaN(d)) + throw new Exception("Illegal value"); + } + + private void DisplayMemory() + { + if (_memVal != string.Empty) + BMemBox.Text = "Memory: " + _memVal; + else + BMemBox.Text = "Memory: [empty]"; + } + + private void CalcResults() + { + double d; + if (_lastOper == Operation.None) + return; + + d = Calc(_lastOper); + Display = d.ToString(CultureInfo.InvariantCulture); + + UpdateDisplay(); + } + + private void UpdateDisplay() + { + DisplayBox.Text = Display == string.Empty ? "0" : Display; + } + + private void AddToDisplay(char c) + { + if (c == '.') + { + if (Display.IndexOf('.', 0) >= 0) //already exists + return; + Display = Display + c; + } + else + { + if (c >= '0' && c <= '9') + { + Display = Display + c; + } + else if (c == '\b') //backspace ? + { + if (Display.Length <= 1) + Display = string.Empty; + else + { + var i = Display.Length; + Display = Display.Remove(i - 1, 1); //remove last char + } + } + } + + UpdateDisplay(); + } + + private void OnMenuAbout(object sender, RoutedEventArgs e) + { + var parent = (Window) MyPanel.Parent; + MessageBox.Show(parent, parent.Title + " - By Jossef Goldberg ", parent.Title, MessageBoxButton.OK, + MessageBoxImage.Information); + } + + private void OnMenuExit(object sender, RoutedEventArgs e) + { + Close(); + } + + private void OnMenuStandard(object sender, RoutedEventArgs e) + { + //((MenuItem)ScientificMenu).IsChecked = false; + StandardMenu.IsChecked = true; //for now always Standard + } + + private void OnMenuScientific(object sender, RoutedEventArgs e) + { + //((MenuItem)StandardMenu).IsChecked = false; + } + + private enum Operation + { + None, + Devide, + Multiply, + Subtract, + Add, + Percent, + Sqrt, + OneX, + Negate + } + + private class PaperTrail + { + private readonly MainWindow _window; + private string _args; + + public PaperTrail(MainWindow window) + { + _window = window; + } + + public void AddArguments(string a) + { + _args = a; + } + + public void AddResult(string r) + { + _window.PaperBox.Text += _args + " = " + r + "\n"; + } + + public void Clear() + { + _window.PaperBox.Text = string.Empty; + _args = string.Empty; + } + } + + private void MenuItem_Click(object sender, RoutedEventArgs e) + { + ContentBorder.Child = new WpfIslandHost(); + + + } + } +} \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/MainWindow.xaml b/Samples/Islands/DrawingIsland/MainWindow.xaml new file mode 100644 index 000000000..e70ae3f67 --- /dev/null +++ b/Samples/Islands/DrawingIsland/MainWindow.xaml @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Memory: [empty] + + + + + + + + + + diff --git a/Samples/Islands/DrawingIsland/MyTextBox.cs b/Samples/Islands/DrawingIsland/MyTextBox.cs new file mode 100644 index 000000000..f42222459 --- /dev/null +++ b/Samples/Islands/DrawingIsland/MyTextBox.cs @@ -0,0 +1,17 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Windows.Controls; +using System.Windows.Input; + +namespace CalculatorDemo +{ + internal sealed class MyTextBox : TextBox + { + protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e) + { + e.Handled = true; + base.OnPreviewGotKeyboardFocus(e); + } + } +} \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/Properties/AssemblyInfo.cs b/Samples/Islands/DrawingIsland/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5dcea412b --- /dev/null +++ b/Samples/Islands/DrawingIsland/Properties/AssemblyInfo.cs @@ -0,0 +1,59 @@ +// // Copyright (c) Microsoft. All rights reserved. +// // Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Reflection; +using System.Runtime.InteropServices; +using System.Windows; + +// 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("CalculatorDemo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CalculatorDemo")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) + )] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/Properties/Resources.Designer.cs b/Samples/Islands/DrawingIsland/Properties/Resources.Designer.cs new file mode 100644 index 000000000..66e92c0be --- /dev/null +++ b/Samples/Islands/DrawingIsland/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CalculatorDemo.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CalculatorDemo.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Samples/Islands/DrawingIsland/Properties/Resources.resx b/Samples/Islands/DrawingIsland/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Samples/Islands/DrawingIsland/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/Properties/Settings.Designer.cs b/Samples/Islands/DrawingIsland/Properties/Settings.Designer.cs new file mode 100644 index 000000000..0610885f1 --- /dev/null +++ b/Samples/Islands/DrawingIsland/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CalculatorDemo.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Samples/Islands/DrawingIsland/Properties/Settings.settings b/Samples/Islands/DrawingIsland/Properties/Settings.settings new file mode 100644 index 000000000..c14891b94 --- /dev/null +++ b/Samples/Islands/DrawingIsland/Properties/Settings.settings @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/README.md b/Samples/Islands/DrawingIsland/README.md new file mode 100644 index 000000000..9d88611d4 --- /dev/null +++ b/Samples/Islands/DrawingIsland/README.md @@ -0,0 +1,49 @@ +--- +languages: +- csharp +products: +- windows-wpf +page_type: sample +name: "Calculator Demo" +description: "This sample application is a simple calculator. It demonstrates layout, controls, and some simple animation." +--- +# Calculator Demo +This sample application is a simple calculator. It demonstrates layout, controls, and some simple animation. + +## Build the sample +The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the [repo](https://github.com/microsoft/WPF-Samples?tab=readme-ov-file) page). You can then unzip the entire archive and use the samples in [Visual Studio 2022](https://www.visualstudio.com/wpf-vs). + +[Download the samples ZIP](../../archive/main.zip) + +### Deploying the sample +- Select Build > Deploy Solution. + +### Deploying and running the sample +- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging. + +# Calculator Demo update + +This section shows how we updated the Calculator Demo to give it a Win11 look and feel. + +## Commit 1: Use .net 9 preview 4 (calc_update_use_dotnet9) + +DotNet9 hadn't yet shipped when we made this demo, so we had to use the .net9 preview 4 sdk installer from [here](https://github.com/dotnet/installer). +Also see that we had to add a dotnet9 entry to our nuget.config, we can remove this once preview 4 ships publicly. + +To make the app build with .net 9, we change the csproj file to use net9.0 as the TargetFramework. + +## Commit 2: Use the new WPF Fluent Resource Dictionary (calc_update_fluent) + +For our app to use the new styles, we need to add the Fluent ResourceDictionary to our Application's merged ResourceDictionary. See App.xaml. + +## Commit 3: Now that the new styles are applied, make some tweaks to add polish (calc_update_tweaks) + +We need to make a few tweaks, mostly for layout, to make things look nice: +* We make the default Button style set Horizontal and VerticalAlignment to stretch so that each button fills its grid cell. We add a margin +too so that the buttons have a little space between them. +* We remove the hardcoded height of the Menu bar at the top so that the menu items are fully visible. +* We increase the default size of the Window, since the new styles tend to use larger text sizes. +* We define a "GrayButton" Style for all the gray buttons in the calculator UI. We set a background that is gray and translucent so that +the mica background is visible through it. +* We give the "=" button the background and foreground of an accent button. +* On the TextBoxes, we made the text a little larger and the border more subtle. \ No newline at end of file diff --git a/Samples/Islands/DrawingIsland/WpfIslandHost.cs b/Samples/Islands/DrawingIsland/WpfIslandHost.cs new file mode 100644 index 000000000..388787d2b --- /dev/null +++ b/Samples/Islands/DrawingIsland/WpfIslandHost.cs @@ -0,0 +1,65 @@ +using DrawingIslandComponents; +using Microsoft.UI.Content; +using Microsoft.UI.Dispatching; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Interop; +using Windows.UI; + +namespace CalculatorDemo +{ + internal class WpfIslandHost : HwndHost + { + protected override HandleRef BuildWindowCore(HandleRef hwndParent) + { + _compositor = new Microsoft.UI.Composition.Compositor(); + + _desktopChildSiteBridge = Microsoft.UI.Content.DesktopChildSiteBridge.Create( + _compositor, + new Microsoft.UI.WindowId((ulong)hwndParent.Handle)); + + //SetupGreenRectangleIsland(); + SetupDrawingIsland(); + + return new HandleRef(null, (nint)_desktopChildSiteBridge.WindowId.Value); + } + + protected override void DestroyWindowCore(HandleRef hwnd) + { + _desktopChildSiteBridge?.Dispose(); + _desktopChildSiteBridge = null; + } + + private void SetupDrawingIsland() + { + _desktopChildSiteBridge.Connect(new DrawingIsland(_compositor).Island); + } + + private void SetupGreenRectangleIsland() + { + _root = _compositor.CreateContainerVisual(); + + var child = _compositor.CreateSpriteVisual(); + child.Brush = _compositor.CreateColorBrush(Color.FromArgb(0xFF, 0x00, 0xCC, 0x00)); + child.Size = new Vector2(400, 400); + + _root.Children.InsertAtTop(child); + + _island = ContentIsland.Create(_root); + _island.RequestSize(new Vector2(200, 200)); + + _desktopChildSiteBridge.Connect(_island); + } + + Microsoft.UI.Composition.Compositor? _compositor; + Microsoft.UI.Composition.ContainerVisual? _root; + Microsoft.UI.Content.DesktopChildSiteBridge? _desktopChildSiteBridge; + Microsoft.UI.Content.ContentIsland? _island; + } +} diff --git a/Samples/Islands/DrawingIsland/appicon.ico b/Samples/Islands/DrawingIsland/appicon.ico new file mode 100644 index 000000000..2cec3ddd0 Binary files /dev/null and b/Samples/Islands/DrawingIsland/appicon.ico differ