最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wpf - My dragvisual appears with a wierd offset - Stack Overflow

programmeradmin2浏览0评论

I have currently the Problem, that my dragged Visual offset is depending on the Current adornerlayer, I tried it with a adorner decorater but it doesn't seem to work.

I want to achieve that the drag visual is centered of my mouse and not depending on which listbox I am picking it from.

My Code looks like following:

public void HandleDragOver(ListBox p_CurrentListBox, DragEventArgs p_E)
{
    if (CurrentDragAdorner != null && CurrentAdornerLayer != null)
    {
        Point Pos = p_E.GetPosition(CurrentAdornerLayer);

        CurrentDragAdorner.UpdatePosition(
             Pos.X ,
              Pos.Y
        );

        if (p_CurrentListBox.Items.Count == 0 || FindDropTarget( p_E.OriginalSource as DependencyObject, p_CurrentListBox) != null)
            p_E.Effects = DragDropEffects.Move;
        else
            p_E.Effects = DragDropEffects.None;

        p_E.Handled = true;
    }
}

My UpdatePosition is like that

   public void UpdatePosition(double p_LeftOffset, double p_TopOffset)
   {
       _leftOffset = p_LeftOffset;
       _topOffset = p_TopOffset;
       InvalidateArrange(); 
   }

this is my layout

   <AdornerDecorator>

     <Grid x:Name="MainGrid">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="3*"></ColumnDefinition>
             <ColumnDefinition Width="*"></ColumnDefinition>
         </Grid.ColumnDefinitions>
         <Grid>

             <Grid.RowDefinitions>
                 <RowDefinition Height="Auto"></RowDefinition>
                 <RowDefinition></RowDefinition>
             </Grid.RowDefinitions>
             <ListBox  x:Name="OrderListBox" 
                   Grid.Row="1" 
                   MinHeight="1400"
                   MinWidth="700"
                   ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                   ScrollViewer.CanContentScroll="False"
                   AllowDrop="True"
                   ManipulationBoundaryFeedback="OrderCard_OnManipulationBoundaryFeedback"
                   HorizontalAlignment="Center"
                   Drop="OrderCard_OnDrop"
                   PreviewMouseDown="OrderCard_OnMouseDown"
                   PreviewTouchDown="OrderCard_OnTouchDown"
                   PreviewTouchMove="OrderCard_OnTouchMove"
                   PreviewTouchUp="OrderCard_OnTouchUp"
                   PreviewDragOver="OrderCard_OnDragOver"
                   ItemsSource="{Binding OrderCards}" 
                   HorizontalContentAlignment="Left">
                 <ListBox.ItemTemplate>
                     <DataTemplate>
                         <control:OrderCard></control:OrderCard>
                     </DataTemplate>
                 </ListBox.ItemTemplate>
             </ListBox>
             
         </Grid>
         <Grid Grid.Column="1">
             <Grid.RowDefinitions>
                 <RowDefinition Height="Auto"></RowDefinition>
                 <RowDefinition></RowDefinition>
             </Grid.RowDefinitions>
             <ListBox x:Name="TabletListBox"
             Grid.Row="1" 
             ScrollViewer.VerticalScrollBarVisibility="Hidden" 
               ScrollViewer.CanContentScroll="False"
               AllowDrop="True"
               ManipulationBoundaryFeedback="OrderCard_OnManipulationBoundaryFeedback"
               HorizontalAlignment="Center"
               PreviewMouseDown="OrderCard_OnMouseDown"
               PreviewTouchDown="OrderCard_OnTouchDown"
               Drop="Tablet_OnDrop"
               DragOver="OrderCard_OnDragOver"
               ItemsSource="{Binding TabletCards}"
               HorizontalContentAlignment="Center">
                 <ListBox.ItemTemplate>
                     <DataTemplate>
                         <control:TabletControl></control:TabletControl>
                     </DataTemplate>
                 </ListBox.ItemTemplate>
             </ListBox>
         </Grid>
     </Grid>
 </AdornerDecorator>

发布评论

评论列表(0)

  1. 暂无评论