"ContainingLayoutPanel is null. Please make sure that it is set."

Oct 16, 2009 at 5:32 AM

Hi Guys,


Has anyone experienced this problem with the code?


"ContainingLayoutPanel is null. Please make sure that it is set."


I have pretty much just taken the code from the "luggage" example.


But as soon as I click on either of the images I get the above error :s


Could somebody please help. I'm just trying to get the basic drag and drop functionality working.




                <my:DragSource AllDropTargetsValid="true"
                                          DropMode="DropDragSource"   DragHandleMode="FullDragSource" Grid.Row="0"
                        <Image Source="Images/camera.png" VerticalAlignment="Center" Width="64" Height="64"></Image>

        <Grid VerticalAlignment="Stretch" HorizontalAlignment="Center" Grid.Row="2" Grid.Column="1" 
                <RowDefinition Height="40"></RowDefinition>
                <RowDefinition Height="200"></RowDefinition>

            <my:DropTarget Width="160" Height="160" HorizontalAlignment="Center"
                                 Grid.Row="1" VerticalAlignment="Top" >
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFD83F00" Offset="0"/>
                        <GradientStop Color="#FFF65E00" Offset="1"/>
                    <my:DragSource DraggingEnabled="True">
            <Image Source="Images/box_open.png" HorizontalAlignment="Center"
                               VerticalAlignment="Center" Width="128" Height="128">



Oct 16, 2009 at 10:40 AM

Hi bobq,

The same issue puzzled me for a while.  You need to set a static property of the SL_Drag_Drop_BaseClasses class as follows -

<font size="2">



InitialValues.ContainingLayoutPanel = this.LayoutRoot;

Just do it in the constructor for your page or user control.  If you look at the code-behind for Page.xaml in the example app I think at about line 40 you can see where its done and this should get everything working for you.

Hope that helps.

Oct 16, 2009 at 11:09 AM



I'm going to add here what I replied by mail to the topic starter as a reference for people with the same problem, but in short: iclements is completely right :-)



It’s indeed a simple thing you’re missing: you need to set the ContainingLayoutPanel.  The Drag Drop manager uses this to calculate the correct positions for dragging/dropping.  This means that, for about 99% of the scenarios, you need to set this panel to the LayoutRoot of your entire application, once, in the main starting point of your app.

So, in the load of your main control, write code to set this like this (assuming you’re having a “using” statement to import the drag drop namespace):

InitialValues.ContainingLayouPanel = this.LayoutRoot;

 In the sample application, you can find the same code.  That should solve your problem.




Oct 17, 2009 at 4:03 AM

Hi Guys,


Thank you very much for all of your help.  You're sugestions worked.

I ow have basic drag and dropping working!.  Excellent controls. Now onto the next challenges!!