1

I'm working on a WPF application with MVVM pattern using Telerik controls.

I'm using telerik:RadListBox for which a collection is bind. My question is when a collection is bound to a RadListBox the collection will be turned as RadListBox or RadListBoxItem ?

XAML:

<telerik:RadListBox x:Name="lstMarketSeries" ItemsSource="{Binding MarketSeriesCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" ItemContainerStyle="{StaticResource DraggableListBoxItem}"DragLeave="lstMarketSeries_DragLeave" Style="{StaticResource myListboxStyle}" SelectionMode="Extended" telerik:StyleManager.Theme="Windows8">
</telerik:RadListBox>

XAML.cs:

/// <summary>
/// Event fired when series are dragged and moved.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lstMarketSeries_DragLeave(object sender, DragEventArgs e)
{

   if (sender is RadListBox) // True
    {

    }

   if(sender is RadListBoxItem) //False Why??
    {

    }
}

When a collection is bound it should be returning as Items Correct? Why am i getting it as RadListBox itself and not RadListBoxItem ?

Now i need that Draggable object as RadListBoxItem. Is there any way?

FYI,

See here ListBoxDragDrop the sender is ListBoxItem and not ListBox

Community
  • 1
  • 1
A Coder
  • 3,039
  • 7
  • 58
  • 129

1 Answers1

1

See the docs.

sender is

The object where the event handler is attached.

That's it.

You are dragging an item, but the event is attached to the container.

<telerik:RadListBox ... DragLeave="lstMarketSeries_DragLeave" ... >`

Therfore when DragLeave event occurs to the RadListBox, the specified handler is fired (which is actually set by you). sender is set to be the RadListBox because the handler is attached to it, not the item.

You have misunderstood the example you're referring to. Read the code of the example carefully. In the example event handler is set to the ItemContainerStyle , which is used to inflate every item. In the example we see the handler, attached to each item individually, therefore sender of the handler is set to be an item rather than the control itself.

If you need sender to de an item you have to do the same - create a style and attach a handler to it.

Community
  • 1
  • 1
Diligent Key Presser
  • 4,183
  • 4
  • 26
  • 34
  • Am i dragging the `RadListBox` or `RadListBoxItem` ? – A Coder Mar 18 '16 at 07:02
  • Check this, http://stackoverflow.com/questions/3350187/wpf-c-rearrange-items-in-listbox-via-drag-and-drop – A Coder Mar 18 '16 at 07:07
  • @SanthoshKumar i see now whats confusing you. See the updated answer. – Diligent Key Presser Mar 18 '16 at 08:20
  • I'm clear now. But what i drag is a `RadListBox` or `RadListBoxItem`? If it is a `RadListBox` how can i change it to `RadListBoxItem` and fire that event? – A Coder Mar 18 '16 at 08:23
  • @SanthoshKumar the same way as your example shows. Create an ItemContainerStyle and attach the handler to it instead of the box. I have no access to the telerik library now so i cant provide an exact code unfortunately. – Diligent Key Presser Mar 18 '16 at 08:24