Starting to drag changes view

May 31, 2010 at 2:53 PM

Hi,

When I try to implement the dragdrop manager like the demo, in a test application, with 2 listboxes, I try to start dragging an item (with a dragbar enabled on top) everything disappears.


It's as if the view gets changed to nothing, like a link.

The xaml is twice this:

<ListBox Height="276" HorizontalAlignment="Left" Margin="12,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="120">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <dd:DropTarget>
                        <dd:DropTarget.Content>
                            <dd:DragSource>
                                <Grid Width="200" Height="40">
                                    <TextBlock Text="{Binding tekst}"
                                        FontSize="14" VerticalAlignment="Center"
                                        HorizontalAlignment="Center"></TextBlock>
                                </Grid>
                                <dd:DragSource.Ghost>
                                    <Grid Width="200" Height="40">
                                        <TextBlock Text="{Binding tekst}"
                                            FontSize="14" VerticalAlignment="Center"
                                            HorizontalAlignment="Center"></TextBlock>
                                    </Grid>
                                </dd:DragSource.Ghost>
                            </dd:DragSource>
                        </dd:DropTarget.Content>
                    </dd:DropTarget>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        public class lstInhoud
        {
            public String tekst { get; set; }
        }

        private ObservableCollection<lstInhoud> leftItems;
        private ObservableCollection<lstInhoud> rightItems;

        public MainPage()
        {
            InitializeComponent();

            leftItems = new ObservableCollection<lstInhoud>();
            rightItems = new ObservableCollection<lstInhoud>();

            for (int i = 0; i < 10; i++)
            {
                leftItems.Add(new lstInhoud { tekst = "LEFT" + i });
                rightItems.Add(new lstInhoud { tekst = "RIGHT" + i });
            }

            listBox1.ItemsSource = leftItems;
            listBox2.ItemsSource = leftItems;
        }

Above is the test data.

 

All help appreciated.

Jun 3, 2010 at 7:07 AM

I guess everything is fine, except that you miss 1 line there

 

 

SL_Drag_Drop_BaseClasses.InitialValues.ContainingLayoutPanel = Me.LayoutRoot;

add it just after calling 

InitializeComponent();

Hope this helps.

Radu

 

Jun 3, 2010 at 8:41 AM
Hi, Thanks a lot. That did the trick, how blind of mine not to notice that line. I'll probably never forget that line again... Regards, Mathias