Silverlight Telerik RadListBox拖放不起作用

本文关键字:不起作用 拖放 RadListBox Telerik Silverlight | 更新日期: 2023-09-27 18:30:02

嘿,谢谢你的光临。

很简单。。只想能够重新排序列表框中的项目,并在拖放时能够更改属性以跟踪更改。预览拖动效果很好,但当我放下时,什么也不会发生。此外,除了被拖动的项目之外,我在拖放管理器OnDrag中没有任何信息。非常感谢您的帮助。谢谢

    <Style TargetType="telerik:RadListBoxItem" x:Key="draggableListBoxItem">
        <Setter Property="telerik:DragDropManager.AllowDrag" Value="True" />
        <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Margin" Value="5,0,0,0"/>
    </Style>
    <Style TargetType="telerik:RadListBox" x:Key="draggableListBox">
        <Setter Property="ItemContainerStyle" Value="{StaticResource draggableListBoxItem}" />
    </Style>
                <telerik:RadListBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="1" Background="White" Margin="10" x:Name="OrderingBox"
                         ItemsSource="{Binding ThingsToBeOrdered}" SelectionMode="Single" AllowDrop="True" Style="{StaticResource draggableListBox}">
                    <telerik:RadListBox.DragVisualProvider>
                        <telerik:ScreenshotDragVisualProvider />
                    </telerik:RadListBox.DragVisualProvider>
                    <telerik:RadListBox.DragDropBehavior>
                        <telerik:ListBoxDragDropBehavior />
                    </telerik:RadListBox.DragDropBehavior>
                    <telerik:RadListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </telerik:RadListBox.ItemsPanel>
                    <telerik:RadListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Center">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="{Binding Id}" Style="{StaticResource textBlockBoldNoMarginStyle}"/>
                                <TextBlock Grid.Column="1" Text="." Style="{StaticResource textBlockBoldNoMarginStyle}"/>
                                <Border Grid.Column="2" Padding="3,2,3,2" BorderBrush="Black" BorderThickness="1" CornerRadius="4" Margin="3,0,0,0">
                                    <Border.Background>
                                        <RadialGradientBrush>
                                            <GradientStop Color="#D9E5F3" Offset="1"/>
                                            <GradientStop Color="#F5F7F9"/>
                                        </RadialGradientBrush>
                                    </Border.Background>
                                    <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" 
                                               VerticalAlignment="Center"
                                               Foreground="#FF002F34" telerik:RadDockPanel.Dock="Top"/>
                                </Border>
                            </Grid>
                        </DataTemplate>
                    </telerik:RadListBox.ItemTemplate>
                </telerik:RadListBox>
        // -------------------------------------------------------
        DragDropManager.AddDropHandler(OrderingBox, OnDrop, true);
    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var items = DragDropPayloadManager.GetDataFromObject(e.Data, typeof (IdNamePair)) as List<object>;
        if (items != null && items.Any())
        {
            if (viewModel.CanWrite)
            {
                // Should only be 1 at a time, but will loop through just in case
                foreach (var draggedItem in items)
                {
                    var item = draggedItem as IdNamePair;
                    if (item != null)
                    {
                        return;
                    }
                }
            }
        }
      // If we get here, we should cancel.. somehow
    }

Silverlight Telerik RadListBox拖放不起作用

终于找到了答案。。。我发布的所有内容都非常好。问题是,出于某种原因,我在ThingsToBeOrdered集合中使用了List而不是ObservableCollection。我一改主意,效果就很好。