Silverlight ListBoxDragDropTarget阻止ListBox填充其父控件
使用Silverlight工具包可以非常轻松地实现基本的拖放操作 不幸的是,包装器Silverlight ListBoxDragDropTarget阻止ListBox填充其父控件,silverlight,listbox,Silverlight,Listbox,使用Silverlight工具包可以非常轻松地实现基本的拖放操作 不幸的是,包装器ListBoxDragDropTarget似乎破坏了ListBox的正常默认行为,即将其自身拉伸到父控件,例如本例中的网格单元 <Grid Background="Yellow"> <toolKit:ListBoxDragDropTarget AllowDrop="True"> <ListBox x:Name="customerListBoxMain"
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
等都无法使其填充父框
如何让
列表框
填充网格
?到目前为止,我最好的方法是监听包装器网格大小的变化,并手动更新大小。(我无法在XAML中工作,因此必须使用事件)
ListBoxDragDropTarget是从内容控件派生的。只需设置水平对齐和 垂直对齐 .....
正如阿切尔所说,设置
水平内容对齐
和垂直内容对齐
是一种方法,但另一种方法可能是将列表框的宽度
和高度
绑定到列表框的实际宽度
和实际高度
:
<toolkit:ListBoxDragDropTarget x:Name="dragdroptarget" AllowDrop="True">
<ListBox x:Name="customerListBoxMain"
DisplayMemberPath="Name"
Width="{Binding ElementName=dragdroptarget, Path=ActualWidth}"
Height="{Binding ElementName=dragdroptarget, Path=ActualHeight}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>
事实证明,目前的拖动功能对我来说不够稳定,我最终得到了各种各样的wierdness。事实上,这确实对我有用!请确保您没有在列表框上设置宽度/高度,并将垂直/水平内容对齐设置为拉伸。刚刚偶然发现这篇文章,这个解决方案对我也很有效。
private void myListBoxWrapper_SizeChanged(object sender, SizeChangedEventArgs e)
{
myListBox.Width = myListBoxWrapper.ActualWidth;
myListBox.Height = myListBoxWrapper.ActualHeight;
}
<toolkit:ListBoxDragDropTarget x:Name="dragdroptarget" AllowDrop="True">
<ListBox x:Name="customerListBoxMain"
DisplayMemberPath="Name"
Width="{Binding ElementName=dragdroptarget, Path=ActualWidth}"
Height="{Binding ElementName=dragdroptarget, Path=ActualHeight}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>