|
此文章由 linkspeed 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 linkspeed 所有!转贴必须注明作者、出处和本声明,并保持内容完整
private IObservable<IEvent<ItemDragEventArgs>> GetItemDragStarting()
{
return
from mouseLeftButtonDown in this.GetMouseLeftButtonDownAlways().ObserveOnDispatcher()
let originalSource = (UIElement)mouseLeftButtonDown.EventArgs.OriginalSource
let offset = GetOffset(mouseLeftButtonDown.EventArgs, originalSource)
from dragStarted in
Application.Current.RootVisual
.GetMouseMove()
.SkipWhile(moveEvent =>
{
Point point = GetOffset(moveEvent.EventArgs, originalSource);
return Math.Abs(point.X - offset.X) < SW.SystemParameters.MinimumHorizontalDragDistance && Math.Abs(point.Y - offset.Y) < SW.SystemParameters.MinimumVerticalDragDistance;
})
.Take(1)
.TakeUntil(Application.Current.RootVisual.GetMouseLeftButtonUpOnSelfAndSiblingsAlways())
let itemsControl = GetItemsControlAncestor(originalSource)
where itemsControl != null
let itemContainer = GetItemContainerAncestor(itemsControl, originalSource)
where itemContainer != null
let itemIndex = IndexFromContainer(itemsControl, itemContainer)
let data = ItemFromContainer(itemsControl, itemContainer)
where data != null
select
Event.Create(
this,
new ItemDragEventArgs
{
DragDecoratorContentMouseOffset = offset,
Data = new SelectionCollection() { new Selection(itemIndex, data) },
DragSource = itemsControl,
AllowedEffects = this.ReadLocalValue(AllowedSourceEffectsProperty) == DependencyProperty.UnsetValue ? GetAllowedEffects(itemsControl) : (SW.DragDropEffects)this.GetValue(AllowedSourceEffectsProperty),
DragDecoratorContent =
new Image
{
Source = new WriteableBitmap(itemContainer, new TranslateTransform())
},
Handled = false,
RemoveDataFromDragSourceAction = (args) => RemoveDataFromItemsControl(itemsControl, args.Data)
});
}
继续,看来这个高人不少。
from mouseLeftButtonDown in this.GetMouseLeftButtonDownAlways().ObserveOnDispatcher()
ObserveOnDispatcher()是干什么用的?
我google了半天居然没有一个像样的解释 |
|