From 369905663746c9b42eef249e16b96b3923db911b Mon Sep 17 00:00:00 2001 From: marcchevaldonne Date: Mon, 29 Jul 2024 23:51:10 +0200 Subject: [PATCH] :testing_tube: updating the ex_ResponsivePage sample to take into account custom visual states triggers --- Samples.sln | 7 + .../ex_ResponsivePage/App.xaml | 15 + .../ex_ResponsivePage/App.xaml.cs | 11 + .../ex_ResponsivePage/AppShell.xaml | 57 +++ .../ex_ResponsivePage/AppShell.xaml.cs | 9 + .../ex_ResponsivePage/ByIdiomPage.xaml | 9 + .../ex_ResponsivePage/ByIdiomPage.xaml.cs | 9 + .../IdiomAndOrientationStateTrigger.cs | 68 +++ .../ex_ResponsivePage/IdiomStateTrigger.cs | 30 ++ .../ex_ResponsivePage/MainPage.xaml | 18 + .../ex_ResponsivePage/MainPage.xaml.cs | 10 + .../ex_ResponsivePage/MauiProgram.cs | 24 + .../OrientationAndIdiomPage.xaml | 9 + .../OrientationAndIdiomPage.xaml.cs | 9 + .../OrientationBackgroundPage.xaml | 34 ++ .../OrientationBackgroundPage.xaml.cs | 9 + .../Platforms/Android/AndroidManifest.xml | 6 + .../Platforms/Android/MainActivity.cs | 10 + .../Platforms/Android/MainApplication.cs | 15 + .../Android/Resources/values/colors.xml | 6 + .../Platforms/MacCatalyst/AppDelegate.cs | 9 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 ++ .../Platforms/MacCatalyst/Program.cs | 15 + .../ex_ResponsivePage/Platforms/Tizen/Main.cs | 16 + .../Platforms/Tizen/tizen-manifest.xml | 15 + .../Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 24 + .../Platforms/Windows/Package.appxmanifest | 46 ++ .../Platforms/Windows/app.manifest | 15 + .../Platforms/iOS/AppDelegate.cs | 9 + .../Platforms/iOS/Info.plist | 32 ++ .../Platforms/iOS/Program.cs | 15 + .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107184 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111168 bytes .../Resources/Images/dotnet_bot.png | Bin 0 -> 69811 bytes .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 45 ++ .../Resources/Styles/MyStyles.xaml | 164 +++++++ .../Resources/Styles/Styles.xaml | 427 ++++++++++++++++++ .../Views/LandscapeView.xaml | 33 ++ .../Views/LandscapeView.xaml.cs | 9 + .../ex_ResponsivePage/Views/PortraitView.xaml | 32 ++ .../Views/PortraitView.xaml.cs | 9 + .../ex_ResponsivePage.csproj | 74 +++ 49 files changed, 1457 insertions(+) create mode 100644 ch02_DesigningViews/ex_ResponsivePage/App.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/App.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/IdiomAndOrientationStateTrigger.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/IdiomStateTrigger.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/MauiProgram.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/OrientationBackgroundPage.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/OrientationBackgroundPage.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Android/AndroidManifest.xml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Android/MainActivity.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Android/MainApplication.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Android/Resources/values/colors.xml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/MacCatalyst/Entitlements.plist create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/MacCatalyst/Info.plist create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/MacCatalyst/Program.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Tizen/Main.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Tizen/tizen-manifest.xml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Windows/App.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Windows/App.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Windows/Package.appxmanifest create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/Windows/app.manifest create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/iOS/AppDelegate.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/iOS/Info.plist create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Platforms/iOS/Program.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Properties/launchSettings.json create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/AppIcon/appicon.svg create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/AppIcon/appiconfg.svg create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Images/dotnet_bot.png create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Raw/AboutAssets.txt create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Splash/splash.svg create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Styles/Colors.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Styles/MyStyles.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Resources/Styles/Styles.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Views/LandscapeView.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Views/LandscapeView.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Views/PortraitView.xaml create mode 100644 ch02_DesigningViews/ex_ResponsivePage/Views/PortraitView.xaml.cs create mode 100644 ch02_DesigningViews/ex_ResponsivePage/ex_ResponsivePage.csproj diff --git a/Samples.sln b/Samples.sln index 6012216..5443e44 100644 --- a/Samples.sln +++ b/Samples.sln @@ -41,6 +41,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_Localization2", "ch06_Ot EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_Localization3", "ch06_Others\ex_Localization3\ex_Localization3.csproj", "{94DB81BA-1FCB-4E65-B1AD-BA68B445C457}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_ResponsivePage", "ch02_DesigningViews\ex_ResponsivePage\ex_ResponsivePage.csproj", "{83D42923-CEFB-48EE-986B-95D584386837}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -113,6 +115,10 @@ Global {94DB81BA-1FCB-4E65-B1AD-BA68B445C457}.Debug|Any CPU.Build.0 = Debug|Any CPU {94DB81BA-1FCB-4E65-B1AD-BA68B445C457}.Release|Any CPU.ActiveCfg = Release|Any CPU {94DB81BA-1FCB-4E65-B1AD-BA68B445C457}.Release|Any CPU.Build.0 = Release|Any CPU + {83D42923-CEFB-48EE-986B-95D584386837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83D42923-CEFB-48EE-986B-95D584386837}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83D42923-CEFB-48EE-986B-95D584386837}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83D42923-CEFB-48EE-986B-95D584386837}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -133,5 +139,6 @@ Global {9F174F30-18D0-4B6B-A8E0-A4D0EB12FBEE} = {CD52E1B3-6246-4940-88A1-1313E1273839} {17CBE4C6-9579-4B76-9520-F902C932C535} = {CD52E1B3-6246-4940-88A1-1313E1273839} {94DB81BA-1FCB-4E65-B1AD-BA68B445C457} = {CD52E1B3-6246-4940-88A1-1313E1273839} + {83D42923-CEFB-48EE-986B-95D584386837} = {1E07D063-F377-413B-B9A0-FB94AF14B1A9} EndGlobalSection EndGlobal diff --git a/ch02_DesigningViews/ex_ResponsivePage/App.xaml b/ch02_DesigningViews/ex_ResponsivePage/App.xaml new file mode 100644 index 0000000..ccd0de4 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/ch02_DesigningViews/ex_ResponsivePage/App.xaml.cs b/ch02_DesigningViews/ex_ResponsivePage/App.xaml.cs new file mode 100644 index 0000000..7930120 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/App.xaml.cs @@ -0,0 +1,11 @@ +namespace ex_ResponsivePage; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } +} diff --git a/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml b/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml new file mode 100644 index 0000000..299d07d --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml.cs b/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml.cs new file mode 100644 index 0000000..e89e202 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/AppShell.xaml.cs @@ -0,0 +1,9 @@ +namespace ex_ResponsivePage; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} diff --git a/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml b/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml new file mode 100644 index 0000000..34b2743 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml.cs b/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml.cs new file mode 100644 index 0000000..3a53d72 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/ByIdiomPage.xaml.cs @@ -0,0 +1,9 @@ +namespace ex_ResponsivePage; + +public partial class ByIdiomPage : ContentPage +{ + public ByIdiomPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/ch02_DesigningViews/ex_ResponsivePage/IdiomAndOrientationStateTrigger.cs b/ch02_DesigningViews/ex_ResponsivePage/IdiomAndOrientationStateTrigger.cs new file mode 100644 index 0000000..7d98595 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/IdiomAndOrientationStateTrigger.cs @@ -0,0 +1,68 @@ +namespace ex_ResponsivePage; + +using Microsoft.Maui.Devices; +using Microsoft.Maui.Controls; + +public sealed class IdiomAndOrientationStateTrigger : StateTriggerBase +{ + public IdiomAndOrientationStateTrigger() + { + UpdateState(); + } + + public static readonly BindableProperty IdiomProperty = + BindableProperty.Create("Idiom", typeof(string), typeof(IdiomAndOrientationStateTrigger), "phone"); + + public string Idiom + { + get => GetValue(IdiomProperty) as string; + set => SetValue(IdiomProperty, value); + } + + public DisplayOrientation Orientation + { + get => (DisplayOrientation)GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } + + public static readonly BindableProperty OrientationProperty = + BindableProperty.Create(nameof(Orientation), typeof(DisplayOrientation), typeof(IdiomAndOrientationStateTrigger), null); + + protected override void OnAttached() + { + base.OnAttached(); + + UpdateState(); + DeviceDisplay.MainDisplayInfoChanged += OnInfoPropertyChanged; + } + + protected override void OnDetached() + { + base.OnDetached(); + + DeviceDisplay.MainDisplayInfoChanged -= OnInfoPropertyChanged; + } + + void OnInfoPropertyChanged(object? sender, DisplayInfoChangedEventArgs e) => + UpdateState(); + + void UpdateState() + { + if (string.IsNullOrEmpty(Idiom)) + return; + + var idiom = DeviceIdiom.Create(Idiom); + + var currentOrientation = DeviceDisplay.MainDisplayInfo.Orientation; + + if(currentOrientation == Orientation || Orientation == DisplayOrientation.Unknown) + { + SetActive(DeviceInfo.Current.Idiom == idiom); + } + else + { + SetActive(false); + } + } +} + diff --git a/ch02_DesigningViews/ex_ResponsivePage/IdiomStateTrigger.cs b/ch02_DesigningViews/ex_ResponsivePage/IdiomStateTrigger.cs new file mode 100644 index 0000000..f37b019 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/IdiomStateTrigger.cs @@ -0,0 +1,30 @@ +namespace ex_ResponsivePage; + +public sealed class IdiomStateTrigger : Microsoft.Maui.Controls.StateTriggerBase +{ + public static readonly BindableProperty IdiomProperty = + BindableProperty.Create("Idiom", typeof(string), typeof(IdiomStateTrigger), "phone"); + + public string Idiom + { + get => GetValue(IdiomProperty) as string; + set => SetValue(IdiomProperty, value); + } + + protected override void OnAttached() + { + base.OnAttached(); + + UpdateState(); + } + + void UpdateState() + { + if (string.IsNullOrEmpty(Idiom)) + return; + + var idiom = DeviceIdiom.Create(Idiom); + + SetActive(DeviceInfo.Current.Idiom == idiom); + } +} diff --git a/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml b/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml new file mode 100644 index 0000000..d7a8b8b --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml.cs b/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml.cs new file mode 100644 index 0000000..d8aab4e --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/MainPage.xaml.cs @@ -0,0 +1,10 @@ +namespace ex_ResponsivePage; + +public partial class MainPage : ContentPage +{ + public MainPage() + { + InitializeComponent(); + } +} + diff --git a/ch02_DesigningViews/ex_ResponsivePage/MauiProgram.cs b/ch02_DesigningViews/ex_ResponsivePage/MauiProgram.cs new file mode 100644 index 0000000..66d6263 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/MauiProgram.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.Logging; + +namespace ex_ResponsivePage; + +public static class MauiProgram +{ + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } +} diff --git a/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml b/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml new file mode 100644 index 0000000..d4cd420 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml.cs b/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml.cs new file mode 100644 index 0000000..0918d60 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/OrientationAndIdiomPage.xaml.cs @@ -0,0 +1,9 @@ +namespace ex_ResponsivePage; + +public partial class OrientationAndIdiomPage : ContentPage +{ + public OrientationAndIdiomPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/ch02_DesigningViews/ex_ResponsivePage/OrientationBackgroundPage.xaml b/ch02_DesigningViews/ex_ResponsivePage/OrientationBackgroundPage.xaml new file mode 100644 index 0000000..4101230 --- /dev/null +++ b/ch02_DesigningViews/ex_ResponsivePage/OrientationBackgroundPage.xaml @@ -0,0 +1,34 @@ + + + + + + + +