This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
Added AttachedProperty IsDraggable and IsDragHandle + Logic #178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, this is my first pull request ever 😬
I'll appreciate any feedback!
Also thank you for this awesome library and all the great work you do in general for Avalonia!
Summary
I needed more control over when a control can be dragged and where it needs to be clicked on to be dragged.
To accomplish this I introduced two
AttachedProperty
onCanvasDragBehavior
:CanvasDragBehavior.IsDraggable
can be set directly on the draggable Control to change it's draggability.CanvasDragBehavior.IsDragHandle
can be set on any number of descendants of the draggable Control.IsDragHandle
is not set on any descendant, the whole draggable Control acts as draghandle (current behavior).IsDragHandle
is set on at least one descendant, the draggable control can only be moved by cicking those descendants.To showcase these properties in action, I added
Canvas (Advanced)
-tab to theDraggableDemo
-Project:How does it work?
IsDraggable
IsDragHandle
The approach of setting the property directly on the descendant required moving some of the logic in
OnAttachedToVisualTree()
toOnLoaded()
, since theGetVisualDescendants()
won't get any/all descendants when called from the former.Dependency on Linq
I am using
Where()
andAny()
in the draghandle logic, sinceGetVisualDescendants()
returns anIEnumerable
.Should I use
ToList()
instead and loop over its elements to avoid the theLinq
dependency, or does that not matter?