2011-08-19 53 views
0

在附加的XAML中,您將看到一個列表框。當它綁定到的ItemsSource屬性(在viewmodel中)爲空時,DragDrop操作似乎可用(拖動光標顯示它可以被刪除)。問題是一旦ListBox被綁定,它不再接受丟棄。我可以看到,如果將光標移動到列表框和控件邊緣之間的空間中,我的控件將接受刪除,所以它顯然是列表框的一部分。Silverlight ListBoxDragDropTarget not accepting Drop

有沒有人有任何想法?

<UserControl x:Class="SilverWare.Avrio.Presentation.Silverlight.Controls.MenuPanelDesigner" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:converters="clr-namespace:SilverWare.Avrio.Presentation.Silverlight.ValueConverters" 
xmlns:controlToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
mc:Ignorable="d" 
d:DesignHeight="600" d:DesignWidth="500" 
MouseLeftButtonUp="MenuPanelDesigner_MouseLeftButtonUp" 
MouseMove="MenuPanelDesigner_MouseMoved" 
LostMouseCapture="MenuPanelDesigner_LostMouseCapture" 
DataContext="{Binding MenuLayoutDesigner, Source={StaticResource Locator}}" AllowDrop="True"> 
<UserControl.Resources> 
    <DataTemplate x:Key="PanelButtonContainerTemplate"> 
     <Border RenderTransformOrigin="0.5,0.5" MouseLeftButtonDown="MenuPanelDesigner_MouseLeftButtonDown" Width="{Binding PanelButton.DTO.Width}" Height="{Binding PanelButton.DTO.Height}"> 
      <TextBlock Text="{Binding PanelButton.DefaultLabel}" VerticalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" /> 
     </Border> 
    </DataTemplate> 
</UserControl.Resources> 

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="1*" /> 
     <ColumnDefinition Width="Auto" /> 
     <ColumnDefinition Width="1*" /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Border Margin="-4" Background="{Binding SelectedMenuGroup.Panel.BackColorBrush}" CornerRadius="10,10,10,10" Grid.Column="1" AllowDrop="True" /> 
    <controlToolkit:ListBoxDragDropTarget Grid.Column="1" AllowDrop="True"> 
     <ListBox ItemsSource="{Binding SelectedMenuGroup.MenuGroupItems}" Width="495" Height="625" Background="Transparent" 
       ItemTemplate="{StaticResource PanelButtonContainerTemplate}" x:Name="lstMenuItems" BorderBrush="Black" BorderThickness="2" 
       SelectionMode="Extended" SelectedItem="{Binding SelectedMenuGroupItem, Mode=TwoWay}" AllowDrop="True"> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <Canvas AllowDrop="True" /> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemContainerStyle> 
       <Style TargetType="ListBoxItem"> 
        <Setter Property="Padding" Value="0,0,0,0"/> 
        <Setter Property="Canvas.Top" Value="{Binding PanelButton.DTO.Y, Mode=TwoWay}" /> 
        <Setter Property="Canvas.Left" Value="{Binding PanelButton.DTO.X, Mode=TwoWay}" /> 
        <Setter Property="Width" Value="{Binding PanelButton.DTO.Width, Mode=TwoWay}" /> 
        <Setter Property="Height" Value="{Binding PanelButton.DTO.Height, Mode=TwoWay}" /> 
       </Style> 
      </ListBox.ItemContainerStyle> 
     </ListBox> 
    </controlToolkit:ListBoxDragDropTarget> 
    <Button Grid.Row="1" Grid.Column="1" Command="{Binding AddItem}" Content="Add Item" /> 
</Grid> 

回答

0

我剛剛發現的controlToolkit:ListBoxDragDropTarget不拖放當底層ListBox的背景是透明的。改變背景爲別的,它應該工作得很好。