无法在绑定的物品控件之间拖动拖放项目 [英] Unable to drag drop items between bound itemscontrols
问题描述
我们有几个绑定的物品控件,它们都起到放下目标的作用
i需要能够拖放这些物品控件之间的拖放物品。 >问题是项目控件不被拖放框架识别为放置目标
ItemsControl面板
< ItemsPanelTemplate x:Key =TopPipePanelTemplate>
< StackPanel>< / StackPanel>
< / ItemsPanelTemplate>
DataTemplate:
< DataTemplate x:Key =PipeDataItem>
< Ellipse Width =45Height =45Fill ={Binding IsMine,Converter = {StaticResource MyCheckerOwnerToColorConverter}}>< / Ellipse>
< / DataTemplate>
ItemsControl样式:
< Style TargetType ={x:Type ItemsControl}x:Key =ItemsControlStyle>
< Setter Property =ItemTemplateValue ={StaticResource PipeDataItem}>< / Setter>
< Setter Property =AllowDropValue =True>< / Setter>
< EventSetter Event =DropHandler =ItemsControlDropTarget>< / EventSetter>
< EventSetter Event =PreviewMouseLeftButtonDownHandler =ItemsControl_MouseLeftButtonDown>< / EventSetter>
< / Style>
**这个例子让我们拿2个ItemsControls:**
< ItemsControl ItemsSource ={Binding Path = Pipes [23] .Checkers}Style ={StaticResource ItemsControlStyle}/>
< ItemsControl Grid.Column =1ItemsSource ={Binding Path = Pipes [22] .Checkers}Style ={StaticResource ItemsControlStyle}/>
定期显示时:
空(左)一不被认定为放弃目标,尽管它将AllowDrop设置为True,
处理Drop事件(与此屏幕中的所有项目控件一样,查看上面的ItemsControl样式)
现在,当我对项目控件面板颜色突然被识别时:
< ItemsPanelTemplate x:Key =TopPipePanelTemplate >
< StackPanel Background =AliceBlue>< / StackPanel>
< / ItemsPanelTemplate>
好像现在它占用了它占据的整个单元格。
iv尝试将面板设置为VerticalAlignment =Stretch,但这也没有影响
我想知道为什么我的项目控件不被识别为启用,
即使我期望他们占用了这个空间,另外用省略号
的项目控件只能被识别,直到占用内容的椭圆的高度。
任何想法?
只是为了澄清我的意思是识别为放置目标是当你拖动椭圆,你可以
将它放在itemscontrol的顶部。
现在只需将背景设置为透明
面板的默认背景颜色不存在,这意味着命中测试通过它。要让它注册命中测试,例如鼠标悬停事件,您需要给它一个背景颜色。通常我只是使用白色
,虽然你说透明
也可以是一个更好的选择。
此外, StackPanels
通常只占用他们需要的空间。您可能会更好地使用一个面板来扩展所有可用空间,例如 DockPanel
与 LastChildFill =False
,并设置 DockPanel.Dock =Top
在您的项目上
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
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
这篇关于无法在绑定的物品控件之间拖动拖放项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!