Hello Telerik.
I am afraid, I am really stupid, but I don't know how is it possible to use ControlExtensions static method FindItemsControlParent on
ControlExtensions class is defined like that:
Everything is from your Drag and Drop Between ListBoxes with user feedback demo project.
My second question is why do you set the selectedIndex of the itemsSource using the dispatcher. There is no such necesity described in MS help files about SelectedIndex property...
Thank you for any clarification.
I think that it would be a little bit better to signalize the possibility to drop dragged item by directly showing inserted grayed copy of dragged item then your dropCueElement. Something like IPHONE animated panel.
Tom
I am afraid, I am really stupid, but I don't know how is it possible to use ControlExtensions static method FindItemsControlParent on
private void OnDragInfo( object sender, DragDropEventArgs e )
{
if ( e.Options.Status == DragStatus.DragComplete )
{
var listBox = e.Options.Source.FindItemsConrolParent() as ItemsControl;
var itemsSource = listBox.ItemsSource as IList;
var operation = e.Options.Payload as DragDropOperation;
itemsSource.Remove( operation.Payload );
}
}
ControlExtensions class is defined like that:
public static class ControlExtensions
{
public static ItemsControl FindItemsConrolParent( this FrameworkElement target )
{
ItemsControl result = null;
result = target.Parent as ItemsControl;
if ( result != null )
return result;
result = ItemsControl.ItemsControlFromItemContainer( target );
if ( result != null )
return result;
return FindVisualParent<
ItemsControl
>( target );
}
public static T FindVisualParent<
T
>( FrameworkElement target ) where T : FrameworkElement
{
if ( target == null )
return null;
var visParent = VisualTreeHelper.GetParent( target );
var result = visParent as T;
if ( result != null )
return result;
return FindVisualParent<
T
>( visParent as FrameworkElement );
}
public static T GetTemplateChild<
T
>( this Control target, string templtePartName ) where T : FrameworkElement
{
if ( target == null )
throw new ArgumentNullException( "target", "Cannot get the templated child of a null object" );
var childCount = VisualTreeHelper.GetChildrenCount( target );
if ( childCount == 0 )
return null;
return ( VisualTreeHelper.GetChild( target, 0 ) as FrameworkElement ).FindName( templtePartName ) as T;
}
}
Everything is from your Drag and Drop Between ListBoxes with user feedback demo project.
My second question is why do you set the selectedIndex of the itemsSource using the dispatcher. There is no such necesity described in MS help files about SelectedIndex property...
Thank you for any clarification.
I think that it would be a little bit better to signalize the possibility to drop dragged item by directly showing inserted grayed copy of dragged item then your dropCueElement. Something like IPHONE animated panel.
Tom