我正在使用Lesters DragAndDropManager 在我的应用程序中获取拖放功能,我真的很喜欢它的实现方式,但是我有一个小问题,那就是我想在状态栏中的拖动过程中显示鼠标坐标,那么如何我是否将鼠标位置从 DropManager 发送到我的 xaml 代码。
我试图在管理器中添加一个依赖属性,我可以在 xaml 代码中绑定到该属性。
public static readonly DependencyProperty MousePointProperty =
DependencyProperty.RegisterAttached("MousePoint", typeof(Point), typeof(DragDropBehavior),
new FrameworkPropertyMetadata(default(Point)));
public static void SetMousePoint(DependencyObject depObj, bool isSet)
{
depObj.SetValue(MousePointProperty, isSet);
}
public static IDragSourceAdvisor GetMousePoint(DependencyObject depObj)
{
return depObj.GetValue(MousePointProperty) as IDragSourceAdvisor;
}
在 Xaml 中,我像这样绑定到它。
<StatusBar>
<TextBlock Text="{Binding local:DragDropBehavior.MousePoint.X}"/>
</StatusBar>
但是如何在管理器中将 mousecordintation 设置为我的依赖属性?
private static void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
{
if (UpdateEffects(sender, e) == false) return;
//-- Update position of the preview Adorner
Point position = GetMousePosition(sender as UIElement);
//-- Here I Want to do this, but that not posible because the SetMousePoint takes a dependencyObject and not my value.
//-- SetMousePoint(position);
_draggedUIElementAdorner.Left = position.X - _offsetPoint.X;
_draggedUIElementAdorner.Top = position.Y - _offsetPoint.Y;
e.Handled = true;
}
我认为我在这里错了,但我一直坚持如何通过绑定到 DragAndDropManager 来让鼠标协调到 xaml 代码。
谢谢。