views:

99

answers:

2

Its extremely easy with the Silverlight Toolkit to enable basic drag and drop.

http://silverlightfeeds.com/post/1325/Silverlight_Toolkit_adds_DragDrop_targets.aspx

Unfortunately it seems that the wrapper ListBoxDragDropTarget screws up the normal default behavior of a ListBox which is to stretch itself to the parent control - such as a grid cell in this example.

<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>

I end up here (after binding data to the ListBox) with a small listbox resized to fit its contents sitting in the middle of a yellow box.

No amount of HorizontalAlignment=Stretch etc. seems to be able to get it to fill the parent box.

How can I get the ListBox to fill the Grid?

A: 

The best I have so far is listening for the size of the wrapper grid to change, and manually updating the size. (I couldn't get this working in XAML so had to use the event).

<Grid Name="myListBoxWrapper" SizeChanged="myListBoxWrapper_SizeChanged">               
  <controlsToolkit:ListBoxDragDropTarget AllowDrop="True">                  
    <ListBox x:Name="myListBox" >

and in code-behind:

private void myListBoxWrapper_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        myListBox.Width = myListBoxWrapper.ActualWidth;
        myListBox.Height = myListBoxWrapper.ActualHeight;
    }
Simon_Weaver
it turns out that currently the dragging functionality isn't stable enough for me and i ended up with all kinds of wierdness anyway..
Simon_Weaver
A: 

ListBoxDragDropTarget is derived from content control. Just set HorizontalContentAlignment and VerticalContentAlignment.

.....

Archil Bolkvadze