I have a WPF application with a DispatcherTimer in UI Thread.
private int TimeLimit = 500;
private DispatcherTimer _timer;
public MainWindow()
{
_timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(TimeLimit) };
_timer.Tick += TimerTick;
_timer.Start();
InitializeComponent();
}
private void TimerTick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " Timer");
}
And when I hover a button, that implement Drag logic, my DispatcherTimer are holding.
xaml:
<Button Width="200" Height="50" Content="Test" PreviewMouseMove="_MouseMove"/>
code:
private Point startPoint = new Point();
private void _MouseMove(object sender, MouseEventArgs e)
{
System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " MousePosition");
// Get the current mouse position
Point mousePos = e.GetPosition(null);
Vector diff = startPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed &&
Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
{
// Get the dragged Item
Button item = sender as Button;
if (item != null)
{
// Get the data
String contact = (String)item.Content;
// Initialize the drag & drop operation
DataObject dragData = new DataObject("String", contact);
DragDrop.DoDragDrop(item, dragData, DragDropEffects.Move);
}
}
}
I must to use working DispatcherTimer. How can I make friends DoDragDrop and the DispatcherTimer?