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

Data Converter Not Getting Called

2 Answers 52 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 16 Apr 2013, 03:08 AM
I created the a custom class using the steps in the documentation to convert data when dragging and dropping.  For some reason, this code is never called and the conversion never happens.  I set breakpoints in the class and they are never hit.  I don't know what I need to do to get the converter to work.  Could someone please help me figure out why the code in the convert class isn't getting called?

Thank you.

Here is the XAML:
<DataTemplate x:Key="LoadBoardListBoxItemTemplate">
            <StackPanel Orientation="Vertical" Background="{Binding ColorCode, Converter={StaticResource ColorConverter}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <TextBlock Text="{Binding Company.Name}" Margin="3" Foreground="White" Width="200" FontSize="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                <TextBlock Text="{Binding Name}" Margin="3" FontSize="12" Foreground="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Turn Time" FontSize="12" Margin="3" Foreground="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                    <TextBlock Text="{Binding TurnTime}" FontSize="12" Margin="3" Foreground="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
 
<Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
        </Style>



<
telerik:RadListBox
            x:Name="xLoadBoardListBox"
            Grid.Row="3"
            Grid.Column="1"
            ItemsSource="{Binding Trips, Mode=TwoWay}"
            IsEnabled="{Binding ListEnabled, Mode=TwoWay}"
            ItemContainerStyle="{StaticResource DraggableListBoxItem}"
            ItemTemplate="{StaticResource LoadBoardListBoxItemTemplate}"
            AllowDrop="True">
            <telerik:RadListBox.DragVisualProvider>
                <telerik:ScreenshotDragVisualProvider />
            </telerik:RadListBox.DragVisualProvider>
            <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior AllowReorder="True" />
            </telerik:RadListBox.DragDropBehavior>
            <telerik:RadListBox.DataConverter>
                <drag:TripToActualTripConverter />
            </telerik:RadListBox.DataConverter>
 
        </telerik:RadListBox>



This is the C# class:
public class TripToActualTripConverter : DataConverter
    {
        public override string[] GetConvertToFormats()
        {
            return new string[] { typeof(Trip).FullName, typeof(ActualTrip).FullName };
        }
 
        public override object ConvertTo(object data, string format)
        {
            var payload = (IEnumerable)DataObjectHelper.GetData(data, typeof(Trip), false);
            if (payload != null)
            {
                return payload.OfType<Trip>().Select(t => new ActualTrip
                {
                    Company = t.Company,
                    CompanyId = t.CompanyId,
                    Trip = t,
                    TripId = t.TripId,
                    ActualDate = DateTime.Now,
                    TicketNumber = string.Empty,
                    TripNumber = string.Empty,
                    ActualTons = 0,
                    Label = t.Name
                });
            }
            return null;
        }
    }

2 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 19 Apr 2013, 11:08 AM
Hi,

We are not aware of any issues concerning data conversion between two RadListBox controls. All you need to do is create to separate DataConverter for each ListBox control and in those converters override the ConvertTo and GetConvertToFormats methods.

I created and attached a sample project for you that shows for to create those DataConverters, hope this is helpful.

All the best,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Brett
Top achievements
Rank 1
answered on 30 Apr 2013, 02:41 PM
Sorry for the late reply.  Thank you for sending me the sample.  I was able to get my code working by following the example.
Tags
ListBox
Asked by
Brett
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Brett
Top achievements
Rank 1
Share this question
or