Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragDrop initiated by Messagebox #83

Closed
hemets opened this issue Jan 31, 2014 · 2 comments
Closed

DragDrop initiated by Messagebox #83

hemets opened this issue Jan 31, 2014 · 2 comments
Assignees
Milestone

Comments

@hemets
Copy link

hemets commented Jan 31, 2014

i have a strange problem with drag&drop in listview, when i have to show a messagebox on item selection.

this can happen, when the currently selected item has unsaved properties and the user selects a new listitem without saving the changes of openend one.

after the messagebox has been closed by user interaction, drag&drop moves the new clicked item in list nearby the mouse position in window .. without a started drag&drop action.

i have no idea how to handle that, or if i do something wrong

Here a simplified example to simulate the problem:

The xaml

<Window x:Class="Admin_TestApp.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
        Title="Window1"
        Height="300"
        Width="555">
    <Grid>
        <ListView dd:DragDrop.IsDragSource="True"
                  dd:DragDrop.IsDropTarget="True"
                  SelectionMode="Single"
                  ItemsSource="{Binding MyCollection}"
                  SelectedItem="{Binding MySelectedItem}">
        </ListView>
    </Grid>
</Window>

The code behind

using Admin_TestApp.ViewModel;
using GalaSoft.MvvmLight.Messaging;
using System.Windows;

namespace Admin_TestApp
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            DataContext = new TestListViewModel();

            Messenger.Reset();
            Messenger.Default.Register<DialogMessage>(this, msg =>
            {
                MessageBoxResult result = MessageBox.Show(msg.Content, msg.Caption, msg.Button, msg.Icon);
                msg.ProcessCallback(result);
            });
        }
    }
}

And the viewmodel

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;

namespace Admin_TestApp.ViewModel
{
    internal class TestListViewModel : ViewModelBase
    {
        public ObservableCollection<string> MyCollection { get; set; }

        public TestListViewModel()
        {
            MyCollection = new ObservableCollection<string>(new List<string>(){
                "List Entry No. 1",
                "List Entry No. 2",
                "List Entry No. 3",
                "List Entry No. 4",
                "List Entry No. 5",
                "List Entry No. 6",
                "List Entry No. 7"
            });
        }

        private string _selectedItem;

        public string MySelectedItem
        {
            get { return _selectedItem; }
            set
            {
                var message = new DialogMessage("Something is happened!",
                    DialogMessageCallbackHandler)
                {
                    Caption = "Something is happened",
                    Button = MessageBoxButton.OK,
                    Icon = MessageBoxImage.Question
                };

                Messenger.Default.Send(message);

                _selectedItem = value;
                RaisePropertyChanged(() => MySelectedItem);
            }
        }

        private void DialogMessageCallbackHandler(MessageBoxResult result)
        {
            // do something
        }
    }
}

you can download the full sample project to simulate the problem here:
https://www.dropbox.com/s/nmtteuib4os91xf/Admin_TestApp.zip

@gpeter
Copy link

gpeter commented May 1, 2014

I ran into this issue as well. Apparently the dialog causes the control to never get the notification that the mouse was released. I resolved it (I think) by inserting 5 lines of code in DragDrop.DragSourcePreviewMouseMove as follows:

    private static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
    {
        if (m_DragInfo != null && !m_DragInProgress)
        {
            if (e.LeftButton == MouseButtonState.Released)       // start insertion
            {
                m_DragInfo = null;
                return;
            }                                           // end insertion

            var dragStart = m_DragInfo.DragStartPosition;

This makes sure the mouse is still down before starting a drag.

@hemets
Copy link
Author

hemets commented May 28, 2014

Thank you very much, i will try this as soon as possible!

geetings, andi

@punker76 punker76 added this to the v0.1.4 milestone May 28, 2014
@punker76 punker76 self-assigned this May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants