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

 

cheers.

 

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

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



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

                    </my:DragSource>
                </my:DropTarget.Content>
            </my:DropTarget>



        </Grid>


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

SL_Drag_Drop_BaseClasses.

</font>

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.

Coordinator
Oct 16, 2009 at 11:09 AM

Hello,

 

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.

"

 

Greets,
Kev. 

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