diff --git a/samples/ControlGallery/AppShell.razor b/samples/ControlGallery/AppShell.razor index f2999044..94c6330d 100644 --- a/samples/ControlGallery/AppShell.razor +++ b/samples/ControlGallery/AppShell.razor @@ -94,6 +94,7 @@ + @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst) diff --git a/samples/ControlGallery/Views/Gestures/DragAndDropPage.razor b/samples/ControlGallery/Views/Gestures/DragAndDropPage.razor new file mode 100644 index 00000000..69824119 --- /dev/null +++ b/samples/ControlGallery/Views/Gestures/DragAndDropPage.razor @@ -0,0 +1,78 @@ +@using Microsoft.Maui.Layouts + + + + + + + + + + + + + + + + + + + + +@code { + bool _dragInProgress; + + List _colors = + [ + Colors.AliceBlue, + Colors.Aqua, + Colors.Azure, + Colors.Beige, + Colors.Bisque, + Colors.Black, + Colors.Blue, + Colors.Brown, + Colors.BurlyWood, + Colors.Crimson, + Colors.DarkGray, + Colors.CornflowerBlue, + Colors.DarkOliveGreen, + Colors.Fuchsia, + Colors.AliceBlue, + Colors.DarkSeaGreen + ]; + + void DragStarted(DragStartingEventArgs args, Color color) + { + _dragInProgress = true; + args.Data.Properties["Color"] = color; + } + + void Dropped() + { + _dragInProgress = false; + } + + void Delete(DropEventArgs args) + { + var color = (Color)args.Data.Properties["Color"]; + _colors.Remove(color); + } +} diff --git a/src/BlazorBindings.Maui/Elements/DragGestureRecognizer.generated.cs b/src/BlazorBindings.Maui/Elements/DragGestureRecognizer.generated.cs new file mode 100644 index 00000000..aebc92e0 --- /dev/null +++ b/src/BlazorBindings.Maui/Elements/DragGestureRecognizer.generated.cs @@ -0,0 +1,78 @@ +// +// This code was generated by a BlazorBindings.Maui component generator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +using BlazorBindings.Core; +using MC = Microsoft.Maui.Controls; +using Microsoft.AspNetCore.Components; +using System.Threading.Tasks; + +#pragma warning disable MBB001 + +namespace BlazorBindings.Maui.Elements +{ + /// + /// Provides drag gesture recognition and defines the associated events for dragging and dropping. + /// + public partial class DragGestureRecognizer : GestureRecognizer + { + static DragGestureRecognizer() + { + RegisterAdditionalHandlers(); + } + + /// + /// Gets or sets the value which indicates whether the element the gesture recognizer is attached to can be a drag source. + /// + [Parameter] public bool? CanDrag { get; set; } + [Parameter] public EventCallback OnDropCompleted { get; set; } + [Parameter] public EventCallback OnDragStarting { get; set; } + + public new MC.DragGestureRecognizer NativeControl => (MC.DragGestureRecognizer)((BindableObject)this).NativeControl; + + protected override MC.DragGestureRecognizer CreateNativeElement() => new(); + + protected override void HandleParameter(string name, object value) + { + switch (name) + { + case nameof(CanDrag): + if (!Equals(CanDrag, value)) + { + CanDrag = (bool?)value; + NativeControl.CanDrag = CanDrag ?? (bool)MC.DragGestureRecognizer.CanDragProperty.DefaultValue; + } + break; + case nameof(OnDropCompleted): + if (!Equals(OnDropCompleted, value)) + { + void NativeControlDropCompleted(object sender, MC.DropCompletedEventArgs e) => InvokeEventCallback(OnDropCompleted, e); + + OnDropCompleted = (EventCallback)value; + NativeControl.DropCompleted -= NativeControlDropCompleted; + NativeControl.DropCompleted += NativeControlDropCompleted; + } + break; + case nameof(OnDragStarting): + if (!Equals(OnDragStarting, value)) + { + void NativeControlDragStarting(object sender, MC.DragStartingEventArgs e) => InvokeEventCallback(OnDragStarting, e); + + OnDragStarting = (EventCallback)value; + NativeControl.DragStarting -= NativeControlDragStarting; + NativeControl.DragStarting += NativeControlDragStarting; + } + break; + + default: + base.HandleParameter(name, value); + break; + } + } + + static partial void RegisterAdditionalHandlers(); + } +} diff --git a/src/BlazorBindings.Maui/Elements/DropGestureRecognizer.generated.cs b/src/BlazorBindings.Maui/Elements/DropGestureRecognizer.generated.cs new file mode 100644 index 00000000..958af039 --- /dev/null +++ b/src/BlazorBindings.Maui/Elements/DropGestureRecognizer.generated.cs @@ -0,0 +1,83 @@ +// +// This code was generated by a BlazorBindings.Maui component generator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +using BlazorBindings.Core; +using MC = Microsoft.Maui.Controls; +using Microsoft.AspNetCore.Components; +using System.Threading.Tasks; + +#pragma warning disable MBB001 + +namespace BlazorBindings.Maui.Elements +{ + public partial class DropGestureRecognizer : GestureRecognizer + { + static DropGestureRecognizer() + { + RegisterAdditionalHandlers(); + } + + [Parameter] public bool? AllowDrop { get; set; } + [Parameter] public EventCallback OnDragLeave { get; set; } + [Parameter] public EventCallback OnDragOver { get; set; } + [Parameter] public EventCallback OnDrop { get; set; } + + public new MC.DropGestureRecognizer NativeControl => (MC.DropGestureRecognizer)((BindableObject)this).NativeControl; + + protected override MC.DropGestureRecognizer CreateNativeElement() => new(); + + protected override void HandleParameter(string name, object value) + { + switch (name) + { + case nameof(AllowDrop): + if (!Equals(AllowDrop, value)) + { + AllowDrop = (bool?)value; + NativeControl.AllowDrop = AllowDrop ?? (bool)MC.DropGestureRecognizer.AllowDropProperty.DefaultValue; + } + break; + case nameof(OnDragLeave): + if (!Equals(OnDragLeave, value)) + { + void NativeControlDragLeave(object sender, MC.DragEventArgs e) => InvokeEventCallback(OnDragLeave, e); + + OnDragLeave = (EventCallback)value; + NativeControl.DragLeave -= NativeControlDragLeave; + NativeControl.DragLeave += NativeControlDragLeave; + } + break; + case nameof(OnDragOver): + if (!Equals(OnDragOver, value)) + { + void NativeControlDragOver(object sender, MC.DragEventArgs e) => InvokeEventCallback(OnDragOver, e); + + OnDragOver = (EventCallback)value; + NativeControl.DragOver -= NativeControlDragOver; + NativeControl.DragOver += NativeControlDragOver; + } + break; + case nameof(OnDrop): + if (!Equals(OnDrop, value)) + { + void NativeControlDrop(object sender, MC.DropEventArgs e) => InvokeEventCallback(OnDrop, e); + + OnDrop = (EventCallback)value; + NativeControl.Drop -= NativeControlDrop; + NativeControl.Drop += NativeControlDrop; + } + break; + + default: + base.HandleParameter(name, value); + break; + } + } + + static partial void RegisterAdditionalHandlers(); + } +} diff --git a/src/BlazorBindings.Maui/Elements/StackLayout.generated.cs b/src/BlazorBindings.Maui/Elements/StackLayout.generated.cs index 54d48dd6..795d7ead 100644 --- a/src/BlazorBindings.Maui/Elements/StackLayout.generated.cs +++ b/src/BlazorBindings.Maui/Elements/StackLayout.generated.cs @@ -25,8 +25,11 @@ static StackLayout() } /// - /// Gets or sets the value which indicates the direction which child elements are positioned. Default value is . + /// Gets or sets the value which indicates the direction which child elements are positioned. /// + /// + /// A which indicates the direction children layouts flow. The default value is Vertical. + /// [Parameter] public MC.StackOrientation? Orientation { get; set; } public new MC.StackLayout NativeControl => (MC.StackLayout)((BindableObject)this).NativeControl; diff --git a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs index 03b61a4c..a810d1ee 100644 --- a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs +++ b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs @@ -185,6 +185,8 @@ [assembly: GenerateComponent(typeof(SwipeGestureRecognizer))] [assembly: GenerateComponent(typeof(TapGestureRecognizer))] [assembly: GenerateComponent(typeof(PointerGestureRecognizer))] +[assembly: GenerateComponent(typeof(DragGestureRecognizer))] +[assembly: GenerateComponent(typeof(DropGestureRecognizer))] // Compatibility