Unable to drag drop items between bound itemscontrols

自作多情 提交于 2019-12-11 08:23:08

问题


iv'e got several bound itemscontrols which all play the role of of drop target i need to be able to drag drop items between these items controls .

the problem is that the items control's are not recognized as drop targets by the drag drop framework

The ItemsControl Panel :

    <ItemsPanelTemplate x:Key="TopPipePanelTemplate">
            <StackPanel></StackPanel>
    </ItemsPanelTemplate>

The DataTemplate :

    <DataTemplate x:Key="PipeDataItem" >
        <Ellipse Width="45" Height="45" Fill="{Binding IsMine,Converter={StaticResource MyCheckerOwnerToColorConverter}}"></Ellipse>
    </DataTemplate>

The ItemsControl Style :

    <Style TargetType="{x:Type ItemsControl}" x:Key="ItemsControlStyle">
          <Setter Property="ItemTemplate" Value="{StaticResource PipeDataItem}"></Setter>
          <Setter Property="AllowDrop" Value="True"></Setter>                                      
          <EventSetter Event="Drop" Handler="ItemsControlDropTarget"></EventSetter> 
          <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ItemsControl_MouseLeftButtonDown"></EventSetter>      
    </Style>

** for this example lets take 2 of The ItemsControls :**

    <ItemsControl ItemsSource="{Binding Path=Pipes[23].Checkers}" Style="{StaticResource ItemsControlStyle}"/>
    <ItemsControl Grid.Column="1" ItemsSource="{Binding Path=Pipes[22].Checkers}" Style="{StaticResource ItemsControlStyle}"/>

when regularly displayed :

the empty ( Left ) one is not recognized as a drop target although it as AllowDrop set to True and handles the Drop event ( as do all the itemscontrols in this screen , look at ItemsControl Style above )

now when i color the itemscontrol panel it s suddenly is recognized :

    <ItemsPanelTemplate x:Key="TopPipePanelTemplate">
            <StackPanel Background="AliceBlue"></StackPanel>
    </ItemsPanelTemplate>

as if now it takes up the entire cell which it occupies .. iv'e tried setting the panel to VerticalAlignment="Stretch" but this also had no affect

i'm trying to understand why my itemcontrols are not recognized as drop enabled , even though i expect that they take up that space , in addition the itemscontrol with the ellipses is only recognized until the height of the ellipses that occupie it's content .

any ideas ?

just to clarify what i mean by Recognized as drop target is when you drag the ellipse you are able to drop it on top of the itemscontrol .

for now iv'e just set the background as Transparent


回答1:


The default background color of a panel doesn't exist, which means hit tests pass through it. To get it to register hit tests, such as mouse over events, you need to give it a background color. Usually I just use White, although you said Transparent also works and would be a better choice.

In addition, StackPanels will usually only take up the space they need. You might be better off using a Panel that stretches to fill all available space, such as a DockPanel with LastChildFill="False", and set DockPanel.Dock="Top" on your items



来源:https://stackoverflow.com/questions/9646674/unable-to-drag-drop-items-between-bound-itemscontrols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!