Ejemplo n.º 1
0
void DropItemBehavior::OnDragLeave(BaseComponent* sender, const DragEventArgs& e)
{
    ContentControl* control = (ContentControl*)sender;
    Slot* slot = (Slot*)control->GetContent();

    slot->SetIsDragOver(false);

    e.handled = true;
}
Ejemplo n.º 2
0
void DropItemBehavior::OnDrop(BaseComponent*, const DragEventArgs& e)
{
    ContentControl* control = GetAssociatedObject();

    Slot* sourceSlot = (Slot*)e.data;
    Slot* targetSlot = (Slot*)control->GetContent();
    targetSlot->SetIsDragOver(false);

    if (targetSlot->GetIsDropAllowed())
    {
        // Move any item in target slot to the source slot
        sourceSlot->SetItem(targetSlot->GetItem());

        // Move dragged item to the target slot
        targetSlot->SetItem(ViewModel::Instance()->GetDraggedItem());
    }
    else
    {
        e.effects = DragDropEffects_None;
    }

    e.handled = true;
}