2012-08-14 59 views
0

我正在處理ListBoxDragDropTarget,當我拖動N拖放一個項目時,綁定到ListBox的ObservableCollection不會更改其項目順序。SilverLight ListBoxDragDropTarget not changing order

<controlsToolkit:ListBoxDragDropTarget AllowDrop="True" 
               Grid.Row="1" 
               HorizontalContentAlignment="Stretch"    
               VerticalAlignment="Top" 
               Margin="0,10,8,10" 
               ItemDragCompleted="ListBoxDragDropTarget_ItemDragCompleted_1" 
               BorderThickness="0"> 
        <ListBox x:Name="servicesListBox" ItemsSource="{Binding ServiceCollection}" 
          ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
          SelectionChanged="servicesListBox_SelectionChanged_1" 
          SelectedItem="{Binding SelectedService, Mode=TwoWay}" 
          Margin="0,102,0,0" Background="#FF040404" 
          SelectionMode="Extended" 
          Foreground="White" Width="800" HorizontalAlignment="Center" BorderBrush="#FF040404" Height="340" VerticalAlignment="Top" > 
         <ListBox.ItemsPanel> 
          <ItemsPanelTemplate> 
          <controlsToolkit:WrapPanel /> 
          </ItemsPanelTemplate> 
         </ListBox.ItemsPanel> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
          <StackPanel Width="250" Margin="4" Orientation="Horizontal">          
            <TextBlock Text="{Binding Title}" Foreground="{Binding IsDesactivated, Converter={StaticResource OnlineColorConverter}}" 
              HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,0,0,0" Width="190" /> 
          </StackPanel> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
      </controlsToolkit:ListBoxDragDropTarget> 

回答

0

這可能是因爲ObservableCollection中的項目是異構的。當你使用多態時,會發生這種情況,例如如果你有一個ObservableCollection,但它實際上持有MyClass類型的元素。這是ListBoxDragDropTarget的一個錯誤,但是這個控件位於「實驗」質量帶中。

兩個可能的解決方法: