csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.6 KiB
54 lines
2.6 KiB
using System.Threading.Tasks;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Input.Platform;
|
|
|
|
namespace Avalonia.Input
|
|
{
|
|
public static class DragDrop
|
|
{
|
|
/// <summary>
|
|
/// Event which is raised, when a drag-and-drop operation enters the element.
|
|
/// </summary>
|
|
public static RoutedEvent<DragEventArgs> DragEnterEvent = RoutedEvent.Register<DragEventArgs>("DragEnter", RoutingStrategies.Bubble, typeof(DragDrop));
|
|
/// <summary>
|
|
/// Event which is raised, when a drag-and-drop operation leaves the element.
|
|
/// </summary>
|
|
public static RoutedEvent<RoutedEventArgs> DragLeaveEvent = RoutedEvent.Register<RoutedEventArgs>("DragLeave", RoutingStrategies.Bubble, typeof(DragDrop));
|
|
/// <summary>
|
|
/// Event which is raised, when a drag-and-drop operation is updated while over the element.
|
|
/// </summary>
|
|
public static RoutedEvent<DragEventArgs> DragOverEvent = RoutedEvent.Register<DragEventArgs>("DragOver", RoutingStrategies.Bubble, typeof(DragDrop));
|
|
/// <summary>
|
|
/// Event which is raised, when a drag-and-drop operation should complete over the element.
|
|
/// </summary>
|
|
public static RoutedEvent<DragEventArgs> DropEvent = RoutedEvent.Register<DragEventArgs>("Drop", RoutingStrategies.Bubble, typeof(DragDrop));
|
|
|
|
public static AvaloniaProperty<bool> AllowDropProperty = AvaloniaProperty.RegisterAttached<Interactive, bool>("AllowDrop", typeof(DragDrop), inherits: true);
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the given element can be used as the target of a drag-and-drop operation.
|
|
/// </summary>
|
|
public static bool GetAllowDrop(Interactive interactive)
|
|
{
|
|
return interactive.GetValue(AllowDropProperty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a value indicating whether the given interactive can be used as the target of a drag-and-drop operation.
|
|
/// </summary>
|
|
public static void SetAllowDrop(Interactive interactive, bool value)
|
|
{
|
|
interactive.SetValue(AllowDropProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target.
|
|
/// <seealso cref="DataObject"/>
|
|
/// </summary>
|
|
public static Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
|
|
{
|
|
var src = AvaloniaLocator.Current.GetService<IPlatformDragSource>();
|
|
return src?.DoDragDrop(data, allowedEffects) ?? Task.FromResult(DragDropEffects.None);
|
|
}
|
|
}
|
|
}
|