开发者

How to indicate allowable drage & drop targets?

开发者 https://www.devze.com 2023-04-13 02:05 出处:网络
I\'m considering a UI design (using WPF), but I\'m not sure how to implement a critical feature: The user will be assigning needs to resources.There are some rules about what assignments can be made,

I'm considering a UI design (using WPF), but I'm not sure how to implement a critical feature: The user will be assigning needs to resources. There are some rules about what assignments can be made, such as compatibility and availability. I would like to display a list of resources, and a list of needs. The user can make an assignment by dragging a need and dropping it onto an resource.

What I would like to do 开发者_如何转开发is show the user what possible assignments can be made by highlighting all assignable resources for a given need. This should be done when dragging any given need.

(I'm comfortable performing the highlight using a property on the resource ViewModels and triggers in XAML, and performing the drag & drop action.)

I don't see any events that are generic to dragging starting or stopping; they are either relevant to the source element, or to elements that are actively being dragged over. How can I evaluate a method to evaluate compatibility on every resource item when a drag is started?

EDIT:

As I am thinking about this more, it might be better to perform the highlighting function upon selection of the item rather than the start of dragging. As the items will typically be in ListViews or TreeViews, dragging will also cause the item to become selected. Additionally, the user will not have to initiate and hold a drag while considering their choices. As the list of targets may be long, the user may need to scroll to find one they want, which is not practical while dragging.

I can easily listen for the SelectionChanged events to evaluate the potential drop targets.


In WPF the drag drop services are well defined along with indicating applicability of which are valid draggable and droppable visuals for the dragged data.

http://msdn.microsoft.com/en-us/library/ms742859.aspx

EDIT

As per your requirement you need to indicate \ highlight \ focus valid droppable targets when drag starts.

For this the droppable visuals must register themselves for the type of data that is getting dragged. All drop targets will thus be notified when such data that they have registered for is getting dragged i.e. in DragDrop.DoDragDrop(..., <dragged data>, ...) call.

Now this is tricky, but you could use Clipboard services to hold the dragged data. The registered target visuals will be notified by the same Clipboard service when such data is added to the clipboard. You could have a command CanExecute() that constantly executes on the drag - drop view and checks the clipboard data is of the registered data type. If so it will set some view model based boolean property that has been attached against all those valid drop targets to true, that will highlight them thru the attached behavior.

In the case of falling back (drag or drop lost), the clipboard must be cleared.

But ofcourse this is easy said than done.... but worth a try.


While I have updated the question with my plans to pursue another UI approach (highlight upon selection), I have still been pondering what I perceive as a shortcoming in the WPF Drag & Drop services.

Suddenly I realized that the start of dragging calls my code in order to get the data being dragged. I can do whatever I want there, including the triggering of any additional UI effects! With this, it seems a little silly to expect such functionality in the DragDrop class...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号