Preview 3: Complete control implementation with XAML data binding
Major milestone adding full control functionality: Controls Enhanced: - Entry/Editor: Full keyboard input, cursor navigation, selection, clipboard - CollectionView: Data binding, selection highlighting, scrolling - CheckBox/Switch/Slider: Interactive state management - Picker/DatePicker/TimePicker: Dropdown selection with popup overlays - ProgressBar/ActivityIndicator: Animated progress display - Button: Press/release visual states - Border/Frame: Rounded corners, stroke styling - Label: Text wrapping, alignment, decorations - Grid/StackLayout: Margin and padding support Features Added: - DisplayAlert dialogs with button actions - NavigationPage with toolbar and back navigation - Shell with flyout menu navigation - XAML value converters for data binding - Margin support in all layout containers - Popup overlay system for pickers New Samples: - TodoApp: Full CRUD task manager with NavigationPage - ShellDemo: Comprehensive control showcase Removed: - ControlGallery (replaced by ShellDemo) - LinuxDemo (replaced by TodoApp) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,9 @@ public partial class LayoutHandler : ViewHandler<ILayout, SkiaLayoutView>
|
||||
public static IPropertyMapper<ILayout, LayoutHandler> Mapper = new PropertyMapper<ILayout, LayoutHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
[nameof(ILayout.Background)] = MapBackground,
|
||||
["BackgroundColor"] = MapBackgroundColor,
|
||||
[nameof(ILayout.ClipsToBounds)] = MapClipsToBounds,
|
||||
[nameof(IPadding.Padding)] = MapPadding,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -53,8 +55,46 @@ public partial class LayoutHandler : ViewHandler<ILayout, SkiaLayoutView>
|
||||
return new SkiaStackLayout();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaLayoutView platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
|
||||
// Explicitly map BackgroundColor since it may be set before handler creation
|
||||
// (e.g., in ItemTemplates for CollectionView)
|
||||
if (VirtualView is Microsoft.Maui.Controls.VisualElement ve && ve.BackgroundColor != null)
|
||||
{
|
||||
platformView.BackgroundColor = ve.BackgroundColor.ToSKColor();
|
||||
platformView.Invalidate();
|
||||
}
|
||||
|
||||
// Add existing children (important for template-created views)
|
||||
if (VirtualView is ILayout layout && MauiContext != null)
|
||||
{
|
||||
for (int i = 0; i < layout.Count; i++)
|
||||
{
|
||||
var child = layout[i];
|
||||
if (child == null) continue;
|
||||
|
||||
// Create handler for child if it doesn't exist
|
||||
if (child.Handler == null)
|
||||
{
|
||||
child.Handler = child.ToHandler(MauiContext);
|
||||
}
|
||||
|
||||
if (child.Handler?.PlatformView is SkiaView skiaChild)
|
||||
{
|
||||
platformView.AddChild(skiaChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackground(LayoutHandler handler, ILayout layout)
|
||||
{
|
||||
// Don't override if BackgroundColor is explicitly set
|
||||
if (layout is Microsoft.Maui.Controls.VisualElement ve && ve.BackgroundColor != null)
|
||||
return;
|
||||
|
||||
var background = layout.Background;
|
||||
if (background is SolidColorBrush solidBrush && solidBrush.Color != null)
|
||||
{
|
||||
@@ -63,12 +103,36 @@ public partial class LayoutHandler : ViewHandler<ILayout, SkiaLayoutView>
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapBackgroundColor(LayoutHandler handler, ILayout layout)
|
||||
{
|
||||
if (layout is Microsoft.Maui.Controls.VisualElement ve && ve.BackgroundColor != null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = ve.BackgroundColor.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapClipsToBounds(LayoutHandler handler, ILayout layout)
|
||||
{
|
||||
handler.PlatformView.ClipToBounds = layout.ClipsToBounds;
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapPadding(LayoutHandler handler, ILayout layout)
|
||||
{
|
||||
if (layout is IPadding paddable)
|
||||
{
|
||||
var padding = paddable.Padding;
|
||||
handler.PlatformView.Padding = new SKRect(
|
||||
(float)padding.Left,
|
||||
(float)padding.Top,
|
||||
(float)padding.Right,
|
||||
(float)padding.Bottom);
|
||||
handler.PlatformView.InvalidateMeasure();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapAdd(LayoutHandler handler, ILayout layout, object? arg)
|
||||
{
|
||||
if (arg is LayoutHandlerUpdate update)
|
||||
@@ -194,9 +258,16 @@ public partial class GridHandler : LayoutHandler
|
||||
{
|
||||
[nameof(IGridLayout.ColumnSpacing)] = MapColumnSpacing,
|
||||
[nameof(IGridLayout.RowSpacing)] = MapRowSpacing,
|
||||
[nameof(IGridLayout.RowDefinitions)] = MapRowDefinitions,
|
||||
[nameof(IGridLayout.ColumnDefinitions)] = MapColumnDefinitions,
|
||||
};
|
||||
|
||||
public GridHandler() : base(Mapper)
|
||||
public static new CommandMapper<IGridLayout, GridHandler> GridCommandMapper = new(LayoutHandler.CommandMapper)
|
||||
{
|
||||
["Add"] = MapGridAdd,
|
||||
};
|
||||
|
||||
public GridHandler() : base(Mapper, GridCommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -205,6 +276,52 @@ public partial class GridHandler : LayoutHandler
|
||||
return new SkiaGrid();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaLayoutView platformView)
|
||||
{
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Called! VirtualView={VirtualView?.GetType().Name}, PlatformView={platformView?.GetType().Name}, MauiContext={(MauiContext != null ? "set" : "null")}");
|
||||
base.ConnectHandler(platformView);
|
||||
|
||||
// Map definitions on connect
|
||||
if (VirtualView is IGridLayout gridLayout && platformView is SkiaGrid grid && MauiContext != null)
|
||||
{
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Grid has {gridLayout.Count} children, RowDefs={gridLayout.RowDefinitions?.Count ?? 0}");
|
||||
UpdateRowDefinitions(grid, gridLayout);
|
||||
UpdateColumnDefinitions(grid, gridLayout);
|
||||
|
||||
// Add existing children (important for template-created views)
|
||||
for (int i = 0; i < gridLayout.Count; i++)
|
||||
{
|
||||
var child = gridLayout[i];
|
||||
if (child == null) continue;
|
||||
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Child[{i}]: {child.GetType().Name}, Handler={child.Handler?.GetType().Name ?? "null"}");
|
||||
|
||||
// Create handler for child if it doesn't exist
|
||||
if (child.Handler == null)
|
||||
{
|
||||
child.Handler = child.ToHandler(MauiContext);
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Created handler for child[{i}]: {child.Handler?.GetType().Name ?? "failed"}");
|
||||
}
|
||||
|
||||
if (child.Handler?.PlatformView is SkiaView skiaChild)
|
||||
{
|
||||
// Get grid position from attached properties
|
||||
int row = 0, column = 0, rowSpan = 1, columnSpan = 1;
|
||||
if (child is Microsoft.Maui.Controls.View mauiView)
|
||||
{
|
||||
row = Microsoft.Maui.Controls.Grid.GetRow(mauiView);
|
||||
column = Microsoft.Maui.Controls.Grid.GetColumn(mauiView);
|
||||
rowSpan = Microsoft.Maui.Controls.Grid.GetRowSpan(mauiView);
|
||||
columnSpan = Microsoft.Maui.Controls.Grid.GetColumnSpan(mauiView);
|
||||
}
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Adding child[{i}] at row={row}, col={column}");
|
||||
grid.AddChild(skiaChild, row, column, rowSpan, columnSpan);
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"[GridHandler.ConnectHandler] Grid now has {grid.Children.Count} SkiaView children");
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapColumnSpacing(GridHandler handler, IGridLayout layout)
|
||||
{
|
||||
if (handler.PlatformView is SkiaGrid grid)
|
||||
@@ -222,6 +339,79 @@ public partial class GridHandler : LayoutHandler
|
||||
grid.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapRowDefinitions(GridHandler handler, IGridLayout layout)
|
||||
{
|
||||
if (handler.PlatformView is SkiaGrid grid)
|
||||
{
|
||||
UpdateRowDefinitions(grid, layout);
|
||||
grid.InvalidateMeasure();
|
||||
grid.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapColumnDefinitions(GridHandler handler, IGridLayout layout)
|
||||
{
|
||||
if (handler.PlatformView is SkiaGrid grid)
|
||||
{
|
||||
UpdateColumnDefinitions(grid, layout);
|
||||
grid.InvalidateMeasure();
|
||||
grid.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateRowDefinitions(SkiaGrid grid, IGridLayout layout)
|
||||
{
|
||||
grid.RowDefinitions.Clear();
|
||||
foreach (var rowDef in layout.RowDefinitions)
|
||||
{
|
||||
var height = rowDef.Height;
|
||||
if (height.IsAbsolute)
|
||||
grid.RowDefinitions.Add(new GridLength((float)height.Value, GridUnitType.Absolute));
|
||||
else if (height.IsAuto)
|
||||
grid.RowDefinitions.Add(GridLength.Auto);
|
||||
else // Star
|
||||
grid.RowDefinitions.Add(new GridLength((float)height.Value, GridUnitType.Star));
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateColumnDefinitions(SkiaGrid grid, IGridLayout layout)
|
||||
{
|
||||
grid.ColumnDefinitions.Clear();
|
||||
foreach (var colDef in layout.ColumnDefinitions)
|
||||
{
|
||||
var width = colDef.Width;
|
||||
if (width.IsAbsolute)
|
||||
grid.ColumnDefinitions.Add(new GridLength((float)width.Value, GridUnitType.Absolute));
|
||||
else if (width.IsAuto)
|
||||
grid.ColumnDefinitions.Add(GridLength.Auto);
|
||||
else // Star
|
||||
grid.ColumnDefinitions.Add(new GridLength((float)width.Value, GridUnitType.Star));
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapGridAdd(GridHandler handler, ILayout layout, object? arg)
|
||||
{
|
||||
if (arg is LayoutHandlerUpdate update && handler.PlatformView is SkiaGrid grid)
|
||||
{
|
||||
var childHandler = update.View.Handler;
|
||||
if (childHandler?.PlatformView is SkiaView skiaView)
|
||||
{
|
||||
// Get grid position from attached properties
|
||||
int row = 0, column = 0, rowSpan = 1, columnSpan = 1;
|
||||
|
||||
if (update.View is Microsoft.Maui.Controls.View mauiView)
|
||||
{
|
||||
row = Microsoft.Maui.Controls.Grid.GetRow(mauiView);
|
||||
column = Microsoft.Maui.Controls.Grid.GetColumn(mauiView);
|
||||
rowSpan = Microsoft.Maui.Controls.Grid.GetRowSpan(mauiView);
|
||||
columnSpan = Microsoft.Maui.Controls.Grid.GetColumnSpan(mauiView);
|
||||
}
|
||||
|
||||
grid.AddChild(skiaView, row, column, rowSpan, columnSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user