Страница:
Customizing Controls with Handlers
Страницы
.NET 7 and .NET MAUI
Blazor Desktop
CLI iOS Simulator Selection
Capturing Binary Logs
Customizing Controls with Handlers
DeviceTests
FAQs
Guidelines for Customization of Controls
Handler Property PR Guidelines
Home
Installing .NET
Known Issues
Memory Leaks
Migrating Xamarin.Forms Effects
Migrating from Preview 10 to 11
Migrating from Preview 7 to 8
Migrating from Preview 8 to 9
Migrating from Preview 9 to 10
Migrating from Xamarin.Forms (Preview)
Migrating from Xamarin.Forms to .NET MAUI
Migrating to Preview 13
Migrating to Preview 14
Migrating to RC1
News
Nightly Builds
Porting Custom Renderers to Handlers
Profiling .NET MAUI Apps
Release Versions
Roadmap
Single Project
Status
Testing
UITests
Upgrading .NET MAUI from .NET 7 to .NET 8
Using Custom Renderers in .NET MAUI
Xamarin.Forms MAUI.Controls Layout Differences
Xamarin.Forms vs .NET MAUI
3
Customizing Controls with Handlers
Gerald Versluis редактировал(а) эту страницу 2021-11-25 15:56:50 +01:00
UI controls in .NET MAUI are rendered via handlers, lightweight classes that map properties and features to bite-sized implementations. Combine that with .NET multi-targeting and you can now succinctly augment any aspect of the native platform control.
The following examples show using compiler directives (#ifdef) to multi-target code based on platform. You can just as easily use platform-specific folders or files to organize such code like
Android\Entry.cs
forEntry
specific customizations, orEntry.android.cs
. The organization is up to you.
This code can live anywhere in your .NET MAUI project.
Example: Debug Rainbows
This would call RandomColor
when setting the BackgroundColor
on any view.
#if ANDROID
Microsoft.Maui.Handlers.ViewHandler.ViewMapper.AppendToMapping(nameof(IView.Background), (h, v) =>
{
(h.NativeView as global::Android.Views.View).SetBackgroundColor(RandomColor());
});
#endif
Example: Remove Android Entry Underline
#if ANDROID
Microsoft.Maui.Handlers.EntryHandler.EntryMapper.AppendToMapping("NoUnderline", (h, v) =>
{
h.NativeView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
});
#endif
Example: Accessibility Testing
#if ENABLE_TEST_CLOUD
Microsoft.Maui.Handlers.Handlers.ViewHandler.ViewMapper(nameof(IView.AutomationId), (h, v) =>
{
(h.NativeView as global::Android.Views.View).ContentDescription = v.AutomationId;
});
#endif
General Info
- How to Contribute
- Handler Property PR Guidelines
- Official Documentation
- Roadmap
- FAQs
- Nightly Builds
- Releases