コード例 #1
0
        public void HandleDrop(object sender, DragEventArgs e)
        {
            DbComparisonViewModel viewModel = (DbComparisonViewModel)this.DataContext;

            if (e.Data.GetDataPresent(AppValues.ProfileDataFormat) && viewModel.CanDoClearProfilesCommand(this))
            {
                Border dropTarget = ViewHelpers.FindAncestor <Border>((DependencyObject)e.OriginalSource);

                Profile profile = (Profile)e.Data.GetData(AppValues.ProfileDataFormat);

                if (dropTarget.Name == DbComparisonViewModel.LeftDropTargetElementName)
                {
                    viewModel.LeftProfile = profile;
                }
                else if (dropTarget.Name == DbComparisonViewModel.RightDropTargetElementName)
                {
                    viewModel.RightProfile = profile;
                }
            }
        }
コード例 #2
0
        public void HandleMouseMove(object sender, MouseEventArgs e)
        {
            Point  mousePosition = e.GetPosition(null);
            Vector movement      = startingClick - mousePosition;
            bool   beginDrag     = false;

            beginDrag = (Math.Abs(movement.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(movement.Y) > SystemParameters.MinimumVerticalDragDistance);

            if (e.LeftButton == MouseButtonState.Pressed && beginDrag == true)
            {
                ListBoxItem item = ViewHelpers.FindAncestor <ListBoxItem>((DependencyObject)e.OriginalSource);

                if (item != null)
                {
                    ProfileItemViewModel profileModel = (ProfileItemViewModel)item.DataContext;
                    Profile    profile        = profileModel.Profile;
                    DataObject draggedProfile = new DataObject(AppValues.ProfileDataFormat, profile);
                    DragDrop.DoDragDrop(item, draggedProfile, DragDropEffects.Copy);
                }
            }
        }