-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
57 deletions.
There are no files selected for viewing
55 changes: 0 additions & 55 deletions
55
src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters