From 063dfb4e32680b4b8a8f05b2f83843002feed9fd Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 8 Jul 2021 11:00:51 -0500 Subject: [PATCH] - add rest of the platforms effects --- .../Pages/Core/Effects.xaml.cs | 55 ------- .../Core/{Effects.xaml => EffectsPage.xaml} | 2 +- .../Pages/Core/EffectsPage.xaml.cs | 139 ++++++++++++++++++ 3 files changed, 140 insertions(+), 56 deletions(-) delete mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs rename src/Controls/samples/Controls.Sample/Pages/Core/{Effects.xaml => EffectsPage.xaml} (94%) create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs deleted file mode 100644 index a89ea9055a6d..000000000000 --- a/src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Diagnostics; -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.Platform; - -namespace Maui.Controls.Sample.Pages -{ - public partial class Effects - { - public Effects() - { - InitializeComponent(); - } - } - - public class FocusRoutingEffect : RoutingEffect - { - protected override void OnAttached() - { - base.OnAttached(); - } - - protected override void OnDetached() - { - base.OnDetached(); - } - } - - public class FocusPlatformEffect : PlatformEffect - { - public FocusPlatformEffect() : base() - { - } - -#if WINDOWS - protected override void OnAttached() - { - try - { - (Control as Microsoft.UI.Xaml.Controls.Control).Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Cyan); - (Control as MauiTextBox).BackgroundFocusBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.White); - } - catch (Exception ex) - { - Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message); - } - } -#endif - - protected override void OnDetached() - { - } - } -} \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml similarity index 94% rename from src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml rename to src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml index 5c1c830308f9..92aec89c03c9 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml @@ -2,7 +2,7 @@ diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs new file mode 100644 index 000000000000..3f3320b967db --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs @@ -0,0 +1,139 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using Microsoft.Maui; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Platform; + +namespace Maui.Controls.Sample.Pages +{ + public partial class EffectsPage + { + public EffectsPage() + { + InitializeComponent(); + } + } + + public class FocusRoutingEffect : RoutingEffect + { + } + +#if WINDOWS + public class FocusPlatformEffect : PlatformEffect + { + public FocusPlatformEffect() : base() + { + } + + protected override void OnAttached() + { + try + { + (Control as Microsoft.UI.Xaml.Controls.Control).Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Cyan); + (Control as MauiTextBox).BackgroundFocusBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.White); + } + catch (Exception ex) + { + Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message); + } + + } + + protected override void OnDetached() + { + } + } +#elif __ANDROID__ + public class FocusPlatformEffect : PlatformEffect + { + Android.Graphics.Color originalBackgroundColor = new Android.Graphics.Color(0, 0, 0, 0); + Android.Graphics.Color backgroundColor; + + protected override void OnAttached() + { + try + { + backgroundColor = Android.Graphics.Color.LightGreen; + Control.SetBackgroundColor(backgroundColor); + } + catch (Exception ex) + { + Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message); + } + } + + protected override void OnDetached() + { + } + + protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) + { + base.OnElementPropertyChanged(args); + try + { + if (args.PropertyName == "IsFocused") + { + if (((Android.Graphics.Drawables.ColorDrawable)Control.Background).Color == backgroundColor) + { + Control.SetBackgroundColor(originalBackgroundColor); + } + else + { + Control.SetBackgroundColor(backgroundColor); + } + } + } + catch (Exception ex) + { + Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message); + } + } + } +#elif __IOS__ + public class FocusPlatformEffect : PlatformEffect + { + UIKit.UIColor backgroundColor; + + protected override void OnAttached() + { + try + { + Control.BackgroundColor = backgroundColor = UIKit.UIColor.FromRGB(204, 153, 255); + } + catch (Exception ex) + { + Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message); + } + } + + protected override void OnDetached() + { + } + + protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) + { + base.OnElementPropertyChanged(args); + + try + { + if (args.PropertyName == "IsFocused") + { + if (Control.BackgroundColor == backgroundColor) + { + Control.BackgroundColor = UIKit.UIColor.White; + } + else + { + Control.BackgroundColor = backgroundColor; + } + } + } + catch (Exception ex) + { + Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message); + } + } + } +#endif +} \ No newline at end of file