Auto sizing of DropSource content

Oct 13, 2009 at 8:54 PM

Hi,

I'm having problem with getting a ListBox within a DragSource to auto size. I'm having the following xaml code:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:windows="clr-namespace:System.Windows.Controls;assembly=FloatableWindow" xmlns:SL_Drag_Drop_BaseClasses="clr-namespace:SL_Drag_Drop_BaseClasses;assembly=SL_Drag_Drop_BaseClasses"
    x:Class="SilverlightApplication1.MainPage"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot" Background="White">
        <SL_Drag_Drop_BaseClasses:DropTarget ShowHover="True">
            <SL_Drag_Drop_BaseClasses:DropTarget.Content>
                <SL_Drag_Drop_BaseClasses:DragSource>
                <ListBox />
                </SL_Drag_Drop_BaseClasses:DragSource>
            </SL_Drag_Drop_BaseClasses:DropTarget.Content>
        </SL_Drag_Drop_BaseClasses:DropTarget>

    </Grid>
</UserControl>

Basically what I'm trying to achieve is to have a DropTarget with a listbox in it so that i can drop items to the listbox. If I just put the ListBox within the Grid the Listbox stretches and auto sizes. The DropTarget also auto sizes, but not the DropSource within the DropTarget.

All help is appreciated.


Best Regards,
Jonas

Coordinator
Oct 14, 2009 at 9:21 AM

Hello,

 

if you want to just be able to drop items into the Listbox, have a look at the sample code (included in the full download): that contains a listbox to which you can drag items.  

 

Kind regards,

Kevin.

Oct 14, 2009 at 9:28 AM

Hi Kevin and thanks for the reply :)

 

I am able to drop items in my ListBox as it is now, but what i cannot achieve is to get the listbox to autosize within the drop source. Furthermore, i cannot get a drop source (set as the content to a drop target) to autosize within its droptarget.

It all works when i set a fixed width and height of the listbox and drop source but i want to achieve automatic resizing when i resize the drop target that the drop source resides in.

It can get quite ugly if i have to resize all controls manually within the drop target just to achieve what I want.

Kind Regards,

Jonas

Oct 14, 2009 at 9:52 AM
Edited Oct 14, 2009 at 11:17 AM

Hi Kevin and Jonas.

Confirm, I have the same problem with autosize of ListBox, into DropSource.

Sorry for my poor english.

Kind Regards,

Mosè

 

P.S: A workaround that I use is:

 

Private Sub DropTarget_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles DropTarget.SizeChanged
        ' update the size of DragSource
        Me.DropTarget.Content.Height = e.NewSize.Height
        Me.DropTarget.Content.Width = e.NewSize.Width
        
        ' update the size of container into DragSource, in my case Border
        CType(Me.DropTarget.Content.Content, Border).Height = e.NewSize.Height
        CType(Me.DropTarget.Content.Content, Border).Width = e.NewSize.Width
End Sub