This is a migrated thread and some comments may be shown as answers.

Getting Started with DragDrop

2 Answers 54 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 18 Jun 2014, 03:44 PM
Trying to make my first DragDrop among RadListBox working but not sure what I am missing - but I am sure that I am missing something. I just have two list boxes - one bound to available friends (from where the drag is initiated) and the other one bound to selected friends where the friends are dropped. But at this point, it just shows up as being dragged from the originating Radlistbox - but nothing comes in the other radlistbox. Pls help.
Here is my XAML and ViewModel. How does this work? Whenever I drop a friend - then ViewModel setter is also not called. So - how actually the OtherRadListBox gets bound to the dropped values.
   
<Window.DataContext>
    <local:MainViewModel />
</Window.DataContext>
<Window.Resources>
    <Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem">
        <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
    </Style>
</Window.Resources>
    <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <telerik:RadListBox ItemContainerStyle="{StaticResource DraggableListBoxItem}"
                        AllowDrop="True"
                        Grid.Column="0" ItemsSource="{Binding AvailableDropZones}" DisplayMemberPath="Name">
        <telerik:RadListBox.DragDropBehavior>
            <telerik:ListBoxDragDropBehavior />
        </telerik:RadListBox.DragDropBehavior>
    </telerik:RadListBox>
    <telerik:RadListBox ItemsSource="{Binding SelectedDropZones}" Grid.Column="1" AllowDrop="True" DisplayMemberPath="Id">
        <telerik:RadListBox.DragDropBehavior>
            <telerik:ListBoxDragDropBehavior />
        </telerik:RadListBox.DragDropBehavior>
    </telerik:RadListBox>
</Grid>

public class MainViewModel :ViewModelBase
{
public MainViewModel()
{
ObservableCollection<Friend> list = new ObservableCollection<Friend>();
list.Add(new Friend() { Id = 1, Name = "Andy" });
list.Add(new Friend() { Id = 2, Name = "Josh" });
list.Add(new Friend() { Id = 3, Name = "Smith" });
list.Add(new Friend() { Id = 4, Name = "Andrew" });
AvailableDropZones = list;
}

ObservableCollection<Friend> availeble;
public ObservableCollection<Friend> AvailableDropZones
{
get
{
return availeble;
}
set
{
if (availeble != value)
{
availeble = value;
OnPropertyChanged("AvailableDropZones");
}
}
}

ObservableCollection<Friend> selected;
public ObservableCollection<Friend> SelectedDropZones
{
get
{
return selected;
}
set
{
if (selected != value)
{
selected = value;
OnPropertyChanged("SelectedDropZones");
}
}
}

}

public class Friend
{
public int Id { get; set; }
public string Name { get; set; }
}

2 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 18 Jun 2014, 04:30 PM
Sorry I got the problem. I was not instantiating the SelectedDropZones in the view model.
SelectedDropZones = new ObservableCollection<Friend     
0
Kalin
Telerik team
answered on 19 Jun 2014, 08:20 AM
Hi Andy,

We are glad you have managed to resolve the problem. If you have any other issues or concerns, please do not hesitate to contact us.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
DragAndDrop
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or