From 986e38e0c8189e366ead469dfcb20df08dd39d60 Mon Sep 17 00:00:00 2001 From: michael-hawker <24302614+michael-hawker@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:21:42 -0700 Subject: [PATCH] Add SwitchPresenter samples, missed in #16 --- .../samples/Assets/SwitchPresenter.png | Bin 0 -> 3642 bytes .../samples/Primitives.Samples.csproj | 4 ++ .../Primitives/samples/SwitchPresenter.md | 27 +++++++++ .../SwitchPresenterLayoutSample.xaml | 54 ++++++++++++++++++ .../SwitchPresenterLayoutSample.xaml.cs | 16 ++++++ .../SwitchPresenterValueSample.xaml | 45 +++++++++++++++ .../SwitchPresenterValueSample.xaml.cs | 24 ++++++++ components/Primitives/samples/UniformGrid.md | 2 +- 8 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 components/Primitives/samples/Assets/SwitchPresenter.png create mode 100644 components/Primitives/samples/SwitchPresenter.md create mode 100644 components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml create mode 100644 components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml.cs create mode 100644 components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml create mode 100644 components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml.cs diff --git a/components/Primitives/samples/Assets/SwitchPresenter.png b/components/Primitives/samples/Assets/SwitchPresenter.png new file mode 100644 index 0000000000000000000000000000000000000000..b8daf434272f5ecc9fda11d58c38457b481ebdec GIT binary patch literal 3642 zcmV-A4#n|_P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGcO#lE0O#vZ@A%Oq@4bMqLK~!i%?OJP$ zT~!rc=iEE@&az;kq z+H0-79{YW!wFOv!1z3Ou_zxfn*gkXU?Mw4KJttJn>UBpb#TFdFr2$S6*6?aWA^!J3 zSH!R!4l8wf$NZE-%AUHyZ5Z$P)m!J-}S#rjKSp@3+M()27-Blk%4v@(rtjr zf-I=Rb{S=CkB$h&99i;R=-)~@ZPXjri+eVK@x-L~63y&@`BQ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#+zPEmn`3%V%qOBivto3eEY^d}3rmwD0AO$tju^+;Zu~#&cL35j*8{ zCHRwVK#B_Zuv(o>&c#7Xh)Plnbw2{;pjBu76^$jPw6 zvwKEI?b^p4w`(5$wf*QXFIs(aQbOrKK|3}T)h2d2t2Dsma8+W~S-mdDG0+I!zzb!O zZj}*Q+eIEB>hMbdgwG6*22cD$EM>3_tUHf*xt+jfv={4cw4>er(O$OV(%#S<`e;gU z6O0QLj+pMMtROiAm8XRQBTx8=AHUaH3xPO}9%&}iT8}s;Njmb!aI1KCYD%BzAulid zi5A6HO+LZf!!JHgd3|G%uBM7YEpg(Er-s352P_sn&+ih*EdE zbu3wg(qm-=Sn5F%m{tWGqJ@%|G-3o!8?q&PsTE;^y4b8dF-~28{)WlEZf2^lCy`$8 z=BNPucK<guMGDJij=dsf9=RP)22RBnL{i1CO&*yKSta5&s&w z8q@!!v2mL?S+QhrFxU$TK~6o*MFKk!<;cxj6D$=>I}AS);iz#0I2r_BUvL8BlH(f< zEpRIjBgBF>k`rU@YlP4znD20c1TpQUL;nbx!KgEcX`7=Yj2e?x%>$5XMNTya7C~zVA_gNaV2g@e?2LQk!Dr z=7SrcGd84QxfaC)l$&h2T+TuyMD89GHWy-Q=}lqCD!yeQ$C(R*5}{}YxB@^7yfFY! z)>P(Ei*-#I-&wV`8()6k4%%j)-m|l9X8g$JO6BAvf((ly0RMkW_XuMcFXQiU4R8xfCX59|93F^C&~Wu`Cuq)djJ3c M07*qoM6N<$f`TK-N&o-= literal 0 HcmV?d00001 diff --git a/components/Primitives/samples/Primitives.Samples.csproj b/components/Primitives/samples/Primitives.Samples.csproj index fe8244d6..fcdf49bc 100644 --- a/components/Primitives/samples/Primitives.Samples.csproj +++ b/components/Primitives/samples/Primitives.Samples.csproj @@ -17,6 +17,7 @@ + @@ -39,6 +40,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/components/Primitives/samples/SwitchPresenter.md b/components/Primitives/samples/SwitchPresenter.md new file mode 100644 index 00000000..e7ec2938 --- /dev/null +++ b/components/Primitives/samples/SwitchPresenter.md @@ -0,0 +1,27 @@ +--- +title: SwitchPresenter +author: michael-hawker +description: A XAML ContentPresenter which can act like a switch statement for showing different UI based on a condition. +keywords: switch, logic, switchpresenter, contentpresenter, visibility, triggers, converters +dev_langs: + - csharp +category: Layouts +subcategory: Miscellaneous +discussion-id: 0 +issue-id: 0 +icon: Assets/SwitchPresenter.png +--- + +The `SwitchPresenter` control acts like a switch statement for XAML. It allows a developer to display certain content based on the condition of another value as an alternative to managing multiple Visibility values or complex visual states. + +Unlike traditional approaches of showing/hiding components within a page, the `SwitchPresenter` will only load and attach the matching Case's content to the Visual Tree. + +## Examples + +SwitchPresenter can make it easier to follow complex layout changes or layouts with varying logic that are based on a property, for instance the type of ticketing mode for an airline: + +> [!SAMPLE SwitchPresenterLayoutSample] + +Or it can simply be used to clearly display different outcomes based on some state which can be useful for a `NavigationView` or with a simple enum as in the following example: + +> [!SAMPLE SwitchPresenterValueSample] diff --git a/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml b/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml new file mode 100644 index 00000000..b521a1c5 --- /dev/null +++ b/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml @@ -0,0 +1,54 @@ + + + + + Select an option + Confirmation Code + E-ticket number + Mileage Plan number + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml.cs b/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml.cs new file mode 100644 index 00000000..e5edd4e6 --- /dev/null +++ b/components/Primitives/samples/SwitchPresenter/SwitchPresenterLayoutSample.xaml.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using PrimitivesExperiment.Samples.ConstrainedBox; + +namespace PrimitivesExperiment.Samples.SwitchPresenter; + +[ToolkitSample(id: nameof(SwitchPresenterLayoutSample), "SwitchPresenter Layout", description: $"A sample for showing how to use a {nameof(SwitchPresenter)} for complex layouts.")] +public sealed partial class SwitchPresenterLayoutSample : Page +{ + public SwitchPresenterLayoutSample() + { + this.InitializeComponent(); + } +} diff --git a/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml b/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml new file mode 100644 index 00000000..648ec60c --- /dev/null +++ b/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml.cs b/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml.cs new file mode 100644 index 00000000..0fb2f77e --- /dev/null +++ b/components/Primitives/samples/SwitchPresenter/SwitchPresenterValueSample.xaml.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace PrimitivesExperiment.Samples.SwitchPresenter; + +[ToolkitSample(id: nameof(SwitchPresenterValueSample), "SwitchPresenter Value", description: $"A sample for showing how to use a {nameof(SwitchPresenter)} for state changes from an enum.")] +public sealed partial class SwitchPresenterValueSample : Page +{ + public SwitchPresenterValueSample() + { + this.InitializeComponent(); + } +} + +public enum Animal +{ + Cat, + Dog, + Bunny, + Llama, + Parrot, + Squirrel +} diff --git a/components/Primitives/samples/UniformGrid.md b/components/Primitives/samples/UniformGrid.md index 37c284fc..8ceb0c4e 100644 --- a/components/Primitives/samples/UniformGrid.md +++ b/components/Primitives/samples/UniformGrid.md @@ -6,7 +6,7 @@ keywords: UniformGrid, grid, layout, responsive dev_langs: - csharp category: Layouts -subcategory: Layout +subcategory: Miscellaneous discussion-id: 0 issue-id: 0 icon: Assets/UniformGrid.png