using Microsoft.UI.Xaml; namespace Lattice.UI.DragDrop.WinUI.Behaviors; /// /// Attached properties для DragSource. /// 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; } } }