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

Problem with declarative drag and drop in my RadListBox

1 Answer 98 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 1
Nate asked on 04 Jun 2014, 07:38 AM
The below is my XAML code:

<Window x:Class="CrmActivityTimer.SetRegardingEntities"
        Title="SetRegardingEntities" Height="337" Width="439"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Window.Resources>
        <Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowDrag" Value="True"/>
        </Style>
    </Window.Resources>
    <Grid>           
        <telerik:RadListBox ItemsSource="{Binding MetaData.RetrievedEntityMetaDatas}" HorizontalAlignment="Left" Height="190"
                            Margin="10,57,0,0" VerticalAlignment="Top" Width="182" ItemContainerStyle="{StaticResource DraggableListBoxItem}"
                            DisplayMemberPath="DisplayName.UserLocalizedLabel.Label" AllowDrop="True">
            <telerik:RadListBox.DragVisualProvider>
                <telerik:ListBoxDragVisualProvider />
            </telerik:RadListBox.DragVisualProvider>
            <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior />
            </telerik:RadListBox.DragDropBehavior>
        </telerik:RadListBox>
        <telerik:RadListBox HorizontalAlignment="Left" Height="190" Margin="239,57,0,0" VerticalAlignment="Top" Width="182"
                            ItemsSource="{Binding MetaData.SavedEntityMetaDatas}" ItemContainerStyle="{StaticResource DraggableListBoxItem}"
                            DisplayMemberPath="DisplayName.UserLocalizedLabel.Label" AllowDrop="True">
            <telerik:RadListBox.DragVisualProvider>
                <telerik:ListBoxDragVisualProvider />
            </telerik:RadListBox.DragVisualProvider>
            <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior />
            </telerik:RadListBox.DragDropBehavior>
        </telerik:RadListBox>  
    </Grid>
</Window>

I have followed the guide from the documentation at http://www.telerik.com/help/wpf/radlistbox-features-dragdrop.html, but it does not work. I can pickup an item from the left list, but I cannot drop it in the right list. It appears like on this image: http://i.stack.imgur.com/ADgPS.png. I also cannot reorder the ones on the left. it shows where I want to drop it, but it does not change anything. This is my code-behind:

public partial class SetRegardingEntities
    {
        public SetRegardingEntitiesMetaData MetaData { get; set; }
        public SetRegardingEntities()
        {
            MetaData = new SetRegardingEntitiesMetaData();
            InitializeComponent();
            IEnumerable<string> regardingTargets = CrmConnector.GetServiceAppointmentRegardingTargets();
            List<EntityMetadata> regardingmetadataList = new List<EntityMetadata>();
            foreach (string regardingTarget in regardingTargets)
            {
                regardingmetadataList.Add(CrmConnector.GetMetaDataForEntityName(regardingTarget));
            }
            MetaData.RetrievedEntityMetaDatas = regardingmetadataList.OrderBy(metadata => metadata.DisplayName.UserLocalizedLabel.Label).ToList();
        }
 
        private void btnSaveBetreft_onclick(object sender, RoutedEventArgs e)
        {
            List<string> regardingTargetsList = MetaData.SavedEntityMetaDatas.Select(savedEntityMetaData => savedEntityMetaData.LogicalName).ToList();
            SettingsSaver.SaveRegardingList(regardingTargetsList);
            ActivityTimerContainer activityTimerContainer = new ActivityTimerContainer();
            activityTimerContainer.Show();
            Close();
 
        }
    }
 
    public class SetRegardingEntitiesMetaData : INotifyPropertyChanged
    {
        private List<EntityMetadata> _retrievedEntityMetadatas;
        private List<EntityMetadata> _savedEntityMetadatas;
 
        public List<EntityMetadata> RetrievedEntityMetaDatas
        {
            get { return _retrievedEntityMetadatas; }
            set
            {
                if (_retrievedEntityMetadatas == value)
                {
                    return;
                }
                _retrievedEntityMetadatas = value;
                OnPropertyChanged();
            }
        }
 
        public List<EntityMetadata> SavedEntityMetaDatas
        {
            get { return _savedEntityMetadatas; }
            set
            {
                if (_savedEntityMetadatas == value)
                {
                    return;
                }
                _savedEntityMetadatas = value;
                OnPropertyChanged();
            }
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

The EntityMetaData object is from the Dynamics CRM 2011 SDK.

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 04 Jun 2014, 08:46 AM
Hello Nate,

In order to able to reorder the items in the ListBoxes you would need to set the AllowReorder property of the attached ListBoxDragDropBehavior to true:

<telerik:RadListBox.DragDropBehavior>
    <telerik:ListBoxDragDropBehavior AllowReorder="True" />
</telerik:RadListBox.DragDropBehavior>

As for the other issue if both the ItemsSources are collections of objects of the same type there shouldn't be any issues with the drop of items between the ListBoxes. Please check the attached sample project which I used to test your scenario and let me know if have missed anything that is possibly the cause of the issue.

I'm looking forward to your response.

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
ListBox
Asked by
Nate
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or