未验证 提交 b1ff1b15 编写于 作者: P punker76

refactor: check for same context to get the templates in preview

上级 cf1f5088
...@@ -183,22 +183,29 @@ public static bool HasDragDropPreview(IDragInfo dragInfo, UIElement visualTarget ...@@ -183,22 +183,29 @@ public static bool HasDragDropPreview(IDragInfo dragInfo, UIElement visualTarget
// Check for source template or template selector if there is no target one // Check for source template or template selector if there is no target one
if (template is null && templateSelector is null) if (template is null && templateSelector is null)
{ {
template = isMultiSelection var sourceContext = DragDrop.GetDragDropContext(dragInfo.VisualSource);
? DragDrop.TryGetDragAdornerMultiItemTemplate(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplate(visualSource, sender) var targetContext = visualTarget != null ? DragDrop.GetDragDropContext(visualTarget) : null;
: DragDrop.TryGetDragAdornerTemplate(visualSource, sender); var isSameContext = string.Equals(sourceContext, targetContext) || string.IsNullOrEmpty(targetContext);
templateSelector = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplateSelector(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender);
var useDefaultDragAdorner = template is null && templateSelector is null && DragDrop.GetUseDefaultDragAdorner(visualSource);
if (useDefaultDragAdorner)
{
template = dragInfo.VisualSourceItem.GetCaptureScreenDataTemplate(dragInfo.VisualSourceFlowDirection);
}
if (template is not null) if (isSameContext)
{ {
templateSelector = null; template = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplate(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplate(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplate(visualSource, sender);
templateSelector = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplateSelector(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender);
var useDefaultDragAdorner = template is null && templateSelector is null && DragDrop.GetUseDefaultDragAdorner(visualSource);
if (useDefaultDragAdorner)
{
template = dragInfo.VisualSourceItem.GetCaptureScreenDataTemplate(dragInfo.VisualSourceFlowDirection);
}
if (template is not null)
{
templateSelector = null;
}
} }
} }
...@@ -232,24 +239,31 @@ public void UpdatePreviewPresenter(IDragInfo dragInfo, UIElement visualTarget, U ...@@ -232,24 +239,31 @@ public void UpdatePreviewPresenter(IDragInfo dragInfo, UIElement visualTarget, U
// Get source template or template selector if there is no target one // Get source template or template selector if there is no target one
if (template is null && templateSelector is null) if (template is null && templateSelector is null)
{ {
template = isMultiSelection var sourceContext = DragDrop.GetDragDropContext(dragInfo.VisualSource);
? DragDrop.TryGetDragAdornerMultiItemTemplate(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplate(visualSource, sender) var targetContext = visualTarget != null ? DragDrop.GetDragDropContext(visualTarget) : null;
: DragDrop.TryGetDragAdornerTemplate(visualSource, sender); var isSameContext = string.Equals(sourceContext, targetContext) || string.IsNullOrEmpty(targetContext);
templateSelector = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplateSelector(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender);
itemsPanel = DragDrop.TryGetDragAdornerItemsPanel(visualTarget, sender);
this.UseDefaultDragAdorner = template is null && templateSelector is null && DragDrop.GetUseDefaultDragAdorner(visualSource);
if (this.UseDefaultDragAdorner)
{
template = dragInfo.VisualSourceItem.GetCaptureScreenDataTemplate(dragInfo.VisualSourceFlowDirection);
this.UseDefaultDragAdorner = template is not null;
}
if (template is not null) if (isSameContext)
{ {
templateSelector = null; template = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplate(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplate(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplate(visualSource, sender);
templateSelector = isMultiSelection
? DragDrop.TryGetDragAdornerMultiItemTemplateSelector(visualSource, sender) ?? DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender)
: DragDrop.TryGetDragAdornerTemplateSelector(visualSource, sender);
itemsPanel = DragDrop.TryGetDragAdornerItemsPanel(visualTarget, sender);
this.UseDefaultDragAdorner = template is null && templateSelector is null && DragDrop.GetUseDefaultDragAdorner(visualSource);
if (this.UseDefaultDragAdorner)
{
template = dragInfo.VisualSourceItem.GetCaptureScreenDataTemplate(dragInfo.VisualSourceFlowDirection);
this.UseDefaultDragAdorner = template is not null;
}
if (template is not null)
{
templateSelector = null;
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册