I am able to drag a legend within a XamDataChart. The problem is on subsequent drags the ghost image of the legend gets further away from the cursor. The cursor is in the right spot but the opaque legend is not after the first drag. How do you position the ghost image?
<Grid x:Name="LineGrid" Background="White"> <ig:XamDataChart x:Name="LineChart" DefaultInteraction="DragZoom" HorizontalZoomable="True" HorizontalZoombarVisibility="Visible" VerticalZoomable="True" VerticalZoombarVisibility="Visible" Legend="{Binding ElementName=LineLegend}" PropertyChanged="OnPropertyChanged"> <ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True" DropChannels="ChannelLegend"/> </ig:DragDropManager.DropTarget> </ig:XamDataChart > <ig:Legend x:Name="LineLegend" Content="Legend" HorizontalAlignment="Left" Margin="10,10,0,0" PreviewMouseDown="legend_MouseLeftButtonDown"> <ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" DragChannels="ChannelLegend" Drop="DragSource_Drop"> <ig:DragSource.MoveCursorTemplate> <DataTemplate> <Ellipse Fill="Green" Width="50" Height="50" /> </DataTemplate> </ig:DragSource.MoveCursorTemplate> </ig:DragSource> </ig:DragDropManager.DragSource> </ig:Legend> </Grid>
Hello Jason,
I would recommend against setting the margin, as when you begin dragging, internally we are creating a snapshot or clone of the control that is being dragged for use as the "ghost" control. Included in this clone is the margin, and so when you begin dragging, that margin will go into effect, and the "ghost" will be offset by that margin.
Instead, I would recommend overlaying a transparent Canvas over the XamDataChart, which will serve as the Legend's parent. By doing this, you can move the legend by using the Canvas.SetTop and the Canvas.SetLeft static methods in the Drop event for the Legend. This appears to prevent the ghost's lagging behind the mouse pointer, as the margin will no longer be necessary.
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Yes I am setting the margin. If there is a better way to set the position then let me know. But setting the margin was the only way I could find to change the legend position
Legend targetLegend = new Legend(); targetLegend = legend; Point pos = e.GetPosition(LineGrid); targetLegend.Margin = new Thickness(pos.X - dragPosInLegend.X, pos.Y - dragPosInLegend.Y, 0, 0);
I think I may have reproduced this issue, but I am unsure if my way of dragging the Legend is matching yours. By any chance, are you applying a Margin to the Legend when you drag and drop it? I ask, at it appears that the margin applied to the Legend control is being respected when the drag starts, and this may be what is causing the Legend "image" to be lagging behind the actual drag point. If this is the way that you are repositioning your Legend, please let me know, and I will continue to look into a solution to this particular issue.
If it is not the way that you are repositioning your Legend, would it be possible for you to please shed some light on how you are doing so?
Thank for the response and example project, but in your example, you arent 'dropping' the legend (ie leaving it in place). It's on the second drag where I have the problem.
I have been investigating into this issue that you are reporting, but at the moment, I can't seem to reproduce this behavior that you are seeing. The behavior I am currently seeing is that the Legend of the XamDataChart is dragged, and the "ghost" image of the Legend appears relative to the mouse click and drag that started the dragging operation.
I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 16.1.20161.2056 in Infragistics for WPF 2016 Volume 1.
If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.