Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.WindowsDragAndDropCustomization"
Title="Drag and Drop Windows Platform-Specific">
<Grid Margin="20" RowDefinitions="290,*">

<Border Margin="15" Grid.Row="0">
<StackLayout>
<Label Text="Drag and Drop the items below" FontSize="Large" FontAttributes="Bold"/>
<CollectionView x:Name="CollectionView1">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" Background="LightGray" HeightRequest="30" HorizontalOptions="Fill" Margin="3">
<Label.GestureRecognizers>
<DragGestureRecognizer />
</Label.GestureRecognizers>
</Label>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Border>

<TableView Intent="Settings" Grid.Row="1" >
<TableRoot>
<TableSection Title="Drag Customization">

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Show Glyph" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="ShowGlyphSwitch" IsToggled="True" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Custom Caption" VerticalTextAlignment="Center" Grid.Column="0"/>
<Entry HorizontalOptions="End" WidthRequest="300" Placeholder="Copy" x:Name="CustomCaptionEntry" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Show Caption" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="ShowCaptionSwitch" IsToggled="True" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Show Content" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="ShowContentSwitch" Grid.Column="1" IsToggled="True"/>
</Grid>
</ViewCell>
</TableSection>

</TableRoot>
</TableView>
<Grid.GestureRecognizers>
<DropGestureRecognizer DragOver="DropGestureRecognizer_DragOver" />
</Grid.GestureRecognizers>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using Maui.Controls.Sample.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;

namespace Maui.Controls.Sample.Pages
{
public partial class WindowsDragAndDropCustomization : ContentPage
{
public WindowsDragAndDropCustomization()
{
InitializeComponent();

CollectionView1.ItemsSource = new NameObject[]
{
new NameObject ("First Item"),
new NameObject ("Second Item"),
new NameObject ("Third Item"),
new NameObject ("Fourth Item"),
new NameObject ("Fifth Item"),
new NameObject ("Sixth Item"),
};
}

void DropGestureRecognizer_DragOver(System.Object sender, Microsoft.Maui.Controls.DragEventArgs e)
{
#if WINDOWS
var dragUI = e.PlatformArgs.DragEventArgs.DragUIOverride;
dragUI.IsCaptionVisible = ShowCaptionSwitch.IsToggled;
dragUI.IsGlyphVisible = ShowGlyphSwitch.IsToggled;
dragUI.IsContentVisible = ShowContentSwitch.IsToggled;

dragUI.Caption = string.IsNullOrEmpty (CustomCaptionEntry.Text) ? "Copy" : CustomCaptionEntry.Text;
#endif
}

public class NameObject
{
public NameObject(string name)
{
Name = name;
}

public string Name { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.iOSDragAndDropRequestFullSize"
Title="Drag and Drop iOS Platform-Specific">
<Grid Margin="20" RowDefinitions="300,*">

<Border Margin="15" Grid.Row="0">
<StackLayout>
<Label Text="Drag and Drop the items below" FontSize="Large" FontAttributes="Bold"/>
<CollectionView x:Name="CollectionView1">
<CollectionView.ItemTemplate>
<DataTemplate>
<Entry Text="{Binding Name}">
<Entry.GestureRecognizers>
<DragGestureRecognizer DragStarting="DragGestureRecognizer_DragStarting" />
<DropGestureRecognizer DragOver="DropGestureRecognizer_DragOver" />
</Entry.GestureRecognizers>
</Entry>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Border>

<TableView Intent="Settings" Grid.Row="1" >
<TableRoot>
<TableSection Title="Drag size option">
<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Request Full-Sized Drag Previews" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="fullSizedSwitch" Toggled="FullSized_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>
</TableSection>

<TableSection Title="Content Options">
<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Use drawn image" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="drawnImageSwitch" Toggled="Drawn_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="Use dotnet bot image" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="dotnetBotImageSwitch" Toggled="DotnetBot_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>
</TableSection>
<TableSection Title="Drop Types">
<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="UIDropProposal - Copy" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="copySwitch" IsToggled="True" Toggled="Copy_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="UIDropProposal - Move" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="moveSwitch" Toggled="Move_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>

<ViewCell>
<Grid ColumnDefinitions="3*,*" VerticalOptions="Center" Margin="10,0,5,0">
<Label Text="UIDropProposal - Forbidden" VerticalTextAlignment="Center" Grid.Column="0"/>
<Switch HorizontalOptions="End" x:Name="forbiddenSwitch" Toggled="Forbidden_Switch_Toggled" Grid.Column="1"/>
</Grid>
</ViewCell>

</TableSection>
</TableRoot>
</TableView>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using Maui.Controls.Sample.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;

namespace Maui.Controls.Sample.Pages
{
public partial class iOSDragAndDropRequestFullSize : ContentPage
{
public iOSDragAndDropRequestFullSize()
{
InitializeComponent();

CollectionView1.ItemsSource = new NameObject[]
{
new NameObject ("First Item"),
new NameObject ("Second Item"),
new NameObject ("Third Item"),
new NameObject ("Fourth Item"),
new NameObject ("Fifth Item"),
new NameObject ("Sixth Item"),
};

// Changing the drag preview is not observed working the same as in iOS
#if MACCATALYST
fullSizedSwitch.IsEnabled = false;
drawnImageSwitch.IsEnabled = false;
dotnetBotImageSwitch.IsEnabled = false;
#endif
}

void DragGestureRecognizer_DragStarting(System.Object sender, Microsoft.Maui.Controls.DragStartingEventArgs e)
{
#if IOS || MACCATALYST
if (drawnImageSwitch.IsToggled)
{
Func<UIKit.UIDragPreview> action = () =>
{
var previewParameters = new UIKit.UIDragPreviewParameters();
var funkyPath = new UIKit.UIBezierPath();
funkyPath.MoveTo(new CoreGraphics.CGPoint(0, 0));
funkyPath.AddLineTo(new CoreGraphics.CGPoint(300, 0));
funkyPath.AddLineTo(new CoreGraphics.CGPoint(225, 150));
funkyPath.AddLineTo(new CoreGraphics.CGPoint(300, 300));
funkyPath.AddLineTo(new CoreGraphics.CGPoint(0, 300));
funkyPath.ClosePath();
previewParameters.VisiblePath = funkyPath;

return new UIKit.UIDragPreview(e.PlatformArgs.Sender, previewParameters);
};

e.PlatformArgs.SetPreviewProvider(action);
}

else if (dotnetBotImageSwitch.IsToggled)
{
Func<UIKit.UIDragPreview> action = () =>
{
var image = UIKit.UIImage.FromFile("dotnet_bot.png");

UIKit.UIImageView imageView = new UIKit.UIImageView(image);
imageView.ContentMode = UIKit.UIViewContentMode.Center;
imageView.Frame = new CoreGraphics.CGRect(0, 0, 250, 250);

return new UIKit.UIDragPreview(imageView);
};

e.PlatformArgs.SetPreviewProvider(action);
}


e.PlatformArgs.SetPrefersFullSizePreviews((interaction, session) => { return fullSizedSwitch.IsToggled; });
#endif
}

void Drawn_Switch_Toggled(object sender, ToggledEventArgs e)
{
if (e.Value)
dotnetBotImageSwitch.IsToggled = false;
}

void DotnetBot_Switch_Toggled(object sender, ToggledEventArgs e)
{
if (e.Value)
drawnImageSwitch.IsToggled = false;
}

void DropGestureRecognizer_DragOver(System.Object sender, Microsoft.Maui.Controls.DragEventArgs e)
{
#if IOS || MACCATALYST
if (copySwitch.IsToggled)
e.PlatformArgs.SetDropProposal(new UIKit.UIDropProposal(UIKit.UIDropOperation.Copy));
else if (moveSwitch.IsToggled)
e.PlatformArgs.SetDropProposal(new UIKit.UIDropProposal(UIKit.UIDropOperation.Move));
else if (forbiddenSwitch.IsToggled)
e.PlatformArgs.SetDropProposal(new UIKit.UIDropProposal(UIKit.UIDropOperation.Forbidden));
#endif
}

void FullSized_Switch_Toggled(object sender, ToggledEventArgs e)
{
}

void Copy_Switch_Toggled(object sender, ToggledEventArgs e)
{
if (e.Value)
{
moveSwitch.IsToggled = false;
forbiddenSwitch.IsToggled = false;
}
}

void Move_Switch_Toggled(object sender, ToggledEventArgs e)
{
if (e.Value)
{
copySwitch.IsToggled = false;
forbiddenSwitch.IsToggled = false;
}
}

void Forbidden_Switch_Toggled(object sender, ToggledEventArgs e)
{
if (e.Value)
{
moveSwitch.IsToggled = false;
copySwitch.IsToggled = false;
}
}

public class NameObject
{
public NameObject(string name)
{
Name = name;
}

public string Name { get; set; }
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ protected override IEnumerable<SectionModel> CreateItems()
new SectionModel(typeof(iOSFlyoutPage), "FlyoutPage Shadow",
"This platform-specific controls whether the detail page of a FlyoutPage has shadow applied to it, when revealing the flyout page."),

new SectionModel(typeof(iOSDragAndDropRequestFullSize), "Drag and Drop Gesture Recognizer Platform-Specific",
"This iOS platform-specific controls whether to request full-sized drag shadows and the UIDropProposal types."),

new SectionModel(typeof(iOSHideHomeIndicatorPage), "Hide Home Indicator",
"This iOS platform-specific sets the visibility of the home indicator on a Page."),

Expand Down Expand Up @@ -123,6 +126,9 @@ protected override IEnumerable<SectionModel> CreateItems()
new SectionModel(typeof(WindowsCollapseWidthAdjusterPage), "FlyoutPage Navigation Bar",
"This WinUI platform-specific is used to collapse the navigation bar on a FlyoutPage."),

new SectionModel(typeof(WindowsDragAndDropCustomization), "Drag and Drop Gesture Recognizer Platform-Specific",
"This WinUI platform-specific displays drag and drop customization such as custom drag gylph and text."),

new SectionModel(typeof(WindowsListViewPage), "ListView Selection Mode",
"This WinUI platform-specific controls whether items in a ListView can respond to tap gestures, and hence whether the native ListView fires the ItemClick or Tapped event."),

Expand Down
16 changes: 16 additions & 0 deletions src/Controls/src/Core/DragAndDrop/PlatformDragStartingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PlatformDragStartingEventArgs
internal Foundation.NSItemProvider? ItemProvider { get; private set; }
internal Func<UIKit.UIDragPreview?>? PreviewProvider { get; private set; }
internal UIKit.UIDragItem[]? DragItems { get; private set; }
internal Func<UIKit.UIDragInteraction, UIKit.IUIDragSession, bool>? PrefersFullSizePreviews { get; private set; }

internal PlatformDragStartingEventArgs(UIKit.UIView? sender, UIKit.UIDragInteraction dragInteraction,
UIKit.IUIDragSession dragSession)
Expand Down Expand Up @@ -71,6 +72,21 @@ public void SetDragItems(UIKit.UIDragItem[] dragItems)
DragItems = dragItems;
}

/// <summary>
/// Sets the func that requests to keep drag previews full-sized when dragging begins.
/// </summary>
/// <param name="prefersFullSizePreviews">Func that returns whether to request full size previews.</param>
/// <remarks>
/// The default behavior on iOS is to reduce the size of the drag shadow if not requested here.
/// Even if requested, it is up to the system whether or not to fulfill the request.
/// This method exists inside <see cref="PlatformDragStartingEventArgs"/> since the preview must
/// have this value set when dragging begins.
/// </remarks>
public void SetPrefersFullSizePreviews(Func<UIKit.UIDragInteraction, UIKit.IUIDragSession, bool>? prefersFullSizePreviews)
{
PrefersFullSizePreviews = prefersFullSizePreviews;
}

#elif ANDROID
/// <summary>
/// Gets the native view attached to the event.
Expand Down
Loading