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

Drag and Drop Behaviors with ComboBoxes

2 Answers 366 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 28 Apr 2013, 09:22 AM
I have a RadListBox with an overrided ItemTemplate that uses a RadComboBox as one of its elements. When the combo box's scroll bar is visible, attempting to scroll triggers the drag process in the RadListBox. When I disable drag and drop completely, I am not able to scroll - it appears that the relevant mouse events are being captured by the RadListBox.

Here is the code for the listbox:

<telerik:RadListBox Name="rlbSpices" QueryContinueDrag="rlbSpices_QueryContinueDrag"  telerik:DragDropManager.AllowDrag="True" AllowDrop="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="1" Grid.Column="1" Margin="5" ItemsSource="{Binding RecipeSpices, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemTemplate="{StaticResource SpiceItemTemplate}">
    <telerik:RadListBox.DragVisualProvider>
        <telerik:ScreenshotDragVisualProvider />
    </telerik:RadListBox.DragVisualProvider>
    <telerik:RadListBox.DragDropBehavior>
        <telerik:ListBoxDragDropBehavior AllowReorder="True"  />
    </telerik:RadListBox.DragDropBehavior>
</telerik:RadListBox>

Here is the code for the item template:

<DataTemplate x:Key="SpiceItemTemplate">
    <Grid HorizontalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="30"/>
            <ColumnDefinition Width="25"/>
        </Grid.ColumnDefinitions>
        <local:IngredientCombobox Loaded="IngredientCombobox_Loaded" PreviewMouseMove="IngredientCombobox_PreviewMouseMove" MouseMove="IngredientCombobox_MouseMove" DropDownOpened="IngredientCombobox_DropDownOpened" DropDownClosed="IngredientCombobox_DropDownClosed" Height="20" VerticalAlignment="Top" Grid.Column="0" SelectedItem="{Binding Spice}"/>
        <xctk:DoubleUpDown Grid.Column="1" Height="20" Width="50" Margin="0,0,0,0" VerticalAlignment="Top" FormatString="F2" Value="{Binding Amount}" Increment=".01"  Maximum="1000.00" />
        <TextBlock Grid.Column="2" Margin="5,0,0,0" Text="{Binding Unit.Name}"/>
        <Button Grid.Column="3" Width="25" Height="25" Name="btnRecipeSpiceDelete" Click="btnRecipeSpiceDelete_Click">X</Button>
    </Grid>
</DataTemplate>


I've tried tracking when a combobox is expanded so that I can disable drag/drop at that time, but there seems to be no way to do that effectively. What is the correct way to handle this issue?

2 Answers, 1 is accepted

Sort by
0
Jacob
Top achievements
Rank 1
answered on 28 Apr 2013, 10:18 AM
I got this to work with the following handlers:

private void IngredientCombobox_DropDownOpened(object sender, EventArgs e)
{
    var item = ((FrameworkElement)sender).GetVisualParent<RadListBoxItem>();
    DragDropManager.SetAllowDrag(item, false);
    _isIngredientDropdownOpen = true;
}
 
private void IngredientCombobox_DropDownClosed(object sender, EventArgs e)
{
    var item = ((FrameworkElement)sender).GetVisualParent<RadListBoxItem>();
    DragDropManager.SetAllowDrag(item, true);
    _isIngredientDropdownOpen = false;
}
0
Steven
Top achievements
Rank 1
answered on 06 Aug 2014, 01:17 PM
I realise this is an old post, but I was having almost the exact same issue, albeit using the code from the following: http://www.telerik.com/help/wpf/radlistbox-features-dragdrop.html

The fix for me was to change the overridden RadListBoxItemStyle to use DragDropManager.AllowDrag in place of AllowCapturedDrag, which then allows the mouse drag events on the items in the template itself.


Note that the OP has added the DragDropManager attached property to the entire RadListBox rather than the items themselves, which may be why it was causing issues in that case.
Tags
ListBox
Asked by
Jacob
Top achievements
Rank 1
Answers by
Jacob
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Share this question
or