ItemsPanelTemplate is not a DP

Feb 12, 2011 at 2:43 PM
                    <ItemsControl x:Name="results">
                        <ItemsControl.Template>
                        <ControlTemplate>
                            <toolkit:PanelDragDropTarget>
                                <toolkit:WrapPanel>
                                    <ItemsPresenter />
                                </toolkit:WrapPanel>
                            </toolkit:PanelDragDropTarget>
                        </ControlTemplate>
                    </ItemsControl.Template>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel AllowDrop="True" Background="Transparent"/>
                    </ItemsPanelTemplate>
                </ItemsControl>

I'm tryihng to come up with a solution for enabling drag drop inside an ItemsControl.  This is not an easy one to solve.  I have tried many hacks to make it work, all of which hit dead-ends at one point or another.

The above solution is one of my hacks which have not yet conclusively reached a dead end.

I am here to gain closure.  The above will compile, but at runtime when setting the page which contains this code to the ActiveItem in the "Conductor One Active Item" object it will fail here: 

GetNamedElementsInScope -> "ItemsPanelTemplate is not a DP".

Of course I added a check to "continue" if it is not a DP, but this results in another runtime exception when setting the Screen to ActiveItem.  

Can anyone with greater Caliburn Micro experience come up with an elegant solution or a dirty hack to make this work?  (I'm not sure if the concept itself will even work, but currently my crashes are occurring inside Caliburn Micro.)

Thank you very much for you help.  This is an important issue (not necessarily for Caliburn, but for dragdroptarget framework).  If we can reach a reasonable hack, I think it will help many people. 

Thanks in advance.

 

 

Feb 12, 2011 at 2:57 PM

This is definitely a bug in Caliburn Micro.  Even when not using Caliburn to bind vm to view, I get the same exception thrown in the extension method: "GetNamedElementsInScope" (please read previous post).

Here's code which causes the same issue.  (Note, there is no DragDropTarget element, or Caliburn conventions since I am specifying ItemsSource explicitly. )

 

                    <ItemsControl ItemsSource="{Binding results}">
                        <ItemsControl.Template>
                        <ControlTemplate>
                                <toolkit:WrapPanel>
                                    <ItemsPresenter />
                                </toolkit:WrapPanel>
                        </ControlTemplate>
                        </ItemsControl.Template>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel AllowDrop="True" Background="Transparent"/>
                        </ItemsPanelTemplate>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Content="Test" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

Coordinator
Feb 12, 2011 at 3:09 PM

Can you create a simple solution that demonstrates the problem and email it to me. That would help me to get a fix in faster. You can send it to robertheisenberg at hotmail dot com

Feb 12, 2011 at 5:47 PM

Sure Rob, 

but can you give me a clue as to why Caliburn is trying to bind any view models to views in the above XAML?   I seem to have a gaping hole in my understanding of how CM works, since I thought that by explicity specifying ItemsSource={Binding} I am cutting CM out of the loop.  Therefore, I don't understand why CM would be searching the Visual Tree looking for VMs and dying when it hits the ItemsPanelTemplate.

I would like to fix the issue myself, or at least get a better understanding of how CM works.

Coordinator
Feb 12, 2011 at 6:25 PM

I'm not exactly sure what is happening. It's looking for elements to apply conventions to and something is dying along the way. I don't see anything strange about your xaml, so I'm eager to get to the bottom of this.

Feb 14, 2011 at 6:19 AM

Unfortunately my XAML skills aren't so sharp, because the issue was just that I forgot the <ItemsControl.ItemsPanel> element before ItemsPaneltemplate element.

Also my entire concept was a dead end.  It only enabled dragging on the entire container, not the individual items themselves.  

I just ended up binding my items manually via observable collection change events and removing the ItemsControl so that I could enable dragging on individual items in the panel.  Not sure how reliable this will be, but it's all I can do until I find a better solution.

Sorry for wasting your time.

Feb 14, 2011 at 8:54 AM

Hi

Not sure if this will help with your specific prob' but I use http://code.google.com/p/gong-wpf-dragdrop/ for drag drop ... it's really easy

 

cheers

Stu