Мой код:
MainWindow .xaml
Код: Выделить всё
Код: Выделить всё
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace DragAndDropTest
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
private TextBox draggedTextBox;
public MainWindow()
{
InitializeComponent();
}
private void TextBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
draggedTextBox = sender as TextBox;
}
private void TextBox_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && draggedTextBox != null)
{
draggedTextBox.Dispatcher.Invoke(() =>
{
DragDrop.DoDragDrop(draggedTextBox, draggedTextBox.Text, DragDropEffects.Move);
});
}
}
private void StackPanel_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
string text = (string)e.Data.GetData(DataFormats.Text);
if (sender != draggedTextBox.Parent)
{
var stackPanel = sender as StackPanel;
if (stackPanel != null)
{
var textBox = new TextBox { Text = text };
stackPanel.Children.Add(textBox);
}
var originalStackPanel = draggedTextBox.Parent as StackPanel;
if (originalStackPanel != null)
{
originalStackPanel.Children.Remove(draggedTextBox);
}
}
}
}
}
}
System.InvalidOperationException. Обработка диспетчером приостановлена, но сообщения продолжают обрабатываться в методе TextBox_MouseMove
строка: DragDrop.DoDragDrop(draggedTextBox, draggedTextBox.Text, DragDropEffects.Move);
Не могу найти решение в Интернете.
Можете ли вы сказать мне, что я сделал не так?
С уважением
Подробнее здесь: https://stackoverflow.com/questions/786 ... essing-has
Мобильная версия