Убраны синхронные методы
This commit is contained in:
49
Lattice.UI.DragDrop.WinUI/Behaviors/DragSource.cs
Normal file
49
Lattice.UI.DragDrop.WinUI/Behaviors/DragSource.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user