Posted 14 years ago
by Keith I
Version: 11.1.0542
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
I have a gallery in a ribbon and I get unusual mouse events sent when I show the popup gallery and click on an item in it. This affects drag and drop from the gallery.
I have modified your GalleryInRibbon sample to show the problem by making the changes detailed below:
In MainWindow.xaml, change the DataTemplate used as the ribbon:RibbonGallery.ItemTemplate to be:Add the file MainWindow.xaml.cs with the following code:
When you then run the application, click to show the popup window of the gallery and then press-and-hold-down the left mouse button on an item in the popup. In the output window you will see the console logging. This will show something like the following:
You will see that a mouse-move event is sent immediately (even when the mouse doesn't move) and one or both of the X and Y values will be considerably different in the mouse-move event to that in the mouse-down event.
If you press-and-hold-down the left mouse button on the gallery when it is not showing the popup gallery, then you only get the mouse-down event.
The reason that this causes a problem is that it breaks drag-and-drop. Most drag-and-drop operations are started when X changes by SystemParameters.MinimumHorizontalDragDistance or Y changes by SystemParameters.MinimumVerticalDragDistance. I get a very weird effect relating to focus because drag-drop is started from the popup gallery as soon as you hold the left mouse button down.
Thanks in advance.
I have modified your GalleryInRibbon sample to show the problem by making the changes detailed below:
In MainWindow.xaml, change the DataTemplate used as the ribbon:RibbonGallery.ItemTemplate to be:
<DataTemplate>
<Image Margin="2" Source="{Binding BindsDirectlyToSource=True}" Stretch="None" MouseDown="GalleryImage_PreviewMouseLeftButtonDown" MouseMove="GalleryImage_PreviewMouseMove"/>
</DataTemplate>
using System;
using System.Windows;
namespace ActiproSoftware.Windows.ProductSamples.RibbonSamples.QuickStart.GalleryInRibbon
{
/// <summary>
/// Provides the main window for this sample.
/// </summary>
public partial class MainWindow : ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow
{
/// <summary>
/// Initializes an instance of the <c>MainWindow</c> class.
/// </summary>
public MainWindow()
{
InitializeComponent();
}
private void GalleryImage_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
Point position = e.GetPosition(null);
Console.WriteLine("GalleryImage_PreviewMouseDown X=" + position.X.ToString() + " Y=" + position.Y.ToString() + " sender=" + sender.GetHashCode().ToString());
}
private void GalleryImage_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
Point position = e.GetPosition(null);
Console.WriteLine("GalleryImage_PreviewMouseMove X=" + position.X.ToString() + " Y=" + position.Y.ToString() + " sender=" + sender.GetHashCode().ToString());
}
}
}
GalleryImage_PreviewMouseDown X=466 Y=138 sender=1556506
GalleryImage_PreviewMouseMove X=462 Y=78 sender=1556506
If you press-and-hold-down the left mouse button on the gallery when it is not showing the popup gallery, then you only get the mouse-down event.
The reason that this causes a problem is that it breaks drag-and-drop. Most drag-and-drop operations are started when X changes by SystemParameters.MinimumHorizontalDragDistance or Y changes by SystemParameters.MinimumVerticalDragDistance. I get a very weird effect relating to focus because drag-drop is started from the popup gallery as soon as you hold the left mouse button down.
Thanks in advance.