Initial commit: .NET MAUI Linux Platform
Complete Linux platform implementation for .NET MAUI with:
- 35+ Skia-rendered controls (Button, Label, Entry, CarouselView, etc.)
- Platform services (Clipboard, FilePicker, Notifications, DragDrop, etc.)
- Accessibility support (AT-SPI2, High Contrast)
- HiDPI and Input Method support
- 216 unit tests
- CI/CD workflows
- Project templates
- Documentation
🤖 Generated with Claude Code
This commit is contained in:
74
Handlers/SwitchHandler.Linux.cs
Normal file
74
Handlers/SwitchHandler.Linux.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using Microsoft.Maui.Handlers;
|
||||
|
||||
namespace Microsoft.Maui.Platform;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for Switch control.
|
||||
/// </summary>
|
||||
public partial class SwitchHandler : ViewHandler<ISwitch, SkiaSwitch>
|
||||
{
|
||||
public static IPropertyMapper<ISwitch, SwitchHandler> Mapper = new PropertyMapper<ISwitch, SwitchHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
[nameof(ISwitch.IsOn)] = MapIsOn,
|
||||
[nameof(ISwitch.TrackColor)] = MapTrackColor,
|
||||
[nameof(ISwitch.ThumbColor)] = MapThumbColor,
|
||||
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
||||
};
|
||||
|
||||
public static CommandMapper<ISwitch, SwitchHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
||||
|
||||
public SwitchHandler() : base(Mapper, CommandMapper) { }
|
||||
|
||||
protected override SkiaSwitch CreatePlatformView() => new SkiaSwitch();
|
||||
|
||||
protected override void ConnectHandler(SkiaSwitch platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.Toggled += OnToggled;
|
||||
}
|
||||
|
||||
protected override void DisconnectHandler(SkiaSwitch platformView)
|
||||
{
|
||||
platformView.Toggled -= OnToggled;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
|
||||
private void OnToggled(object? sender, ToggledEventArgs e)
|
||||
{
|
||||
if (VirtualView != null && VirtualView.IsOn != e.Value)
|
||||
{
|
||||
VirtualView.IsOn = e.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapIsOn(SwitchHandler handler, ISwitch @switch)
|
||||
{
|
||||
if (handler.PlatformView.IsOn != @switch.IsOn)
|
||||
{
|
||||
handler.PlatformView.IsOn = @switch.IsOn;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapTrackColor(SwitchHandler handler, ISwitch @switch)
|
||||
{
|
||||
if (@switch.TrackColor != null)
|
||||
handler.PlatformView.OnTrackColor = @switch.TrackColor.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapThumbColor(SwitchHandler handler, ISwitch @switch)
|
||||
{
|
||||
if (@switch.ThumbColor != null)
|
||||
handler.PlatformView.ThumbColor = @switch.ThumbColor.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapIsEnabled(SwitchHandler handler, ISwitch @switch)
|
||||
{
|
||||
handler.PlatformView.IsEnabled = @switch.IsEnabled;
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user