Files
Lattice/Lattice.UI.DragDrop.WinUI/Behaviors/DragSource.cs

49 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.UI.Xaml;
namespace Lattice.UI.DragDrop.WinUI.Behaviors;
/// <summary>
/// Attached properties для DragSource.
/// </summary>
public static class DragSource
{
public static readonly DependencyProperty IsEnabledProperty =
DependencyProperty.RegisterAttached(
"IsEnabled",
typeof(bool),
typeof(DragSource),
new PropertyMetadata(false, OnIsEnabledChanged));
public static readonly DependencyProperty DragDataProperty =
DependencyProperty.RegisterAttached(
"DragData",
typeof(object),
typeof(DragSource),
new PropertyMetadata(null));
public static bool GetIsEnabled(UIElement element) =>
(bool)element.GetValue(IsEnabledProperty);
public static void SetIsEnabled(UIElement element, bool value) =>
element.SetValue(IsEnabledProperty, value);
public static object GetDragData(UIElement element) =>
element.GetValue(DragDataProperty);
public static void SetDragData(UIElement element, object value) =>
element.SetValue(DragDataProperty, value);
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not UIElement element) return;
// TODO: Здесь нужно создать экземпляр WinUIDragSourceBehavior
// и прикрепить его к элементу через DI
// Пока что устанавливаем данные в Tag
if ((bool)e.NewValue)
{
var data = GetDragData(element);
element.Tag = data;
}
}
}