使用Silverlight Toolkit非常容易实现基本的拖放。
http://silverlightfeeds.com/post/1325/Silverlight_Toolkit_adds_DragDrop_targets.aspx
不幸的是,似乎包装器ListBoxDragDropTarget
搞砸了ListBox的正常默认行为,它将自身伸展到父控件 - 例如本例中的网格单元。
<Grid Background="Yellow">
<toolKit:ListBoxDragDropTarget AllowDrop="True">
<ListBox x:Name="customerListBoxMain"
DisplayMemberPath="Name">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolKit:ListBoxDragDropTarget>
</Grid>
我最终在这里(在将数据绑定到ListBox
之后),调整了一个小的列表框以适应位于黄色框中间的内容。
HorizontalAlignment=Stretch
等似乎没有任何数量可以让它填充父框。
如何让ListBox
填充Grid
?
答案 0 :(得分:6)
ListBoxDragDropTarget派生自内容控件。只需设置HorizontalContentAlignment和 VerticalContentAlignment。
.....
答案 1 :(得分:0)
我到目前为止最好的是监听要更改的包装网格的大小,并手动更新大小。 (我无法在XAML中使用它,因此必须使用该事件)。
<Grid Name="myListBoxWrapper" SizeChanged="myListBoxWrapper_SizeChanged">
<controlsToolkit:ListBoxDragDropTarget AllowDrop="True">
<ListBox x:Name="myListBox" >
和代码隐藏:
private void myListBoxWrapper_SizeChanged(object sender, SizeChangedEventArgs e)
{
myListBox.Width = myListBoxWrapper.ActualWidth;
myListBox.Height = myListBoxWrapper.ActualHeight;
}
答案 2 :(得分:0)
正如Archil所说,设置HorizontalContentAlignment
和VerticalContentAlignment
是可行的方法,但另一种方法可能是绑定Width
和Height
ListBox
致ActualWidth
的{{1}}和ActualHeight
:
ListBoxDragDropTarget