0

うまくいけば、これは簡単な質問です。Silverlight Toolkit のを使用して、ある場所から別の場所へのListBoxDragDropTargetドラッグ アンド ドロップを設定していますListBox。イベントを発生させることができないようです。これが私のXAMLコードです:

<toolkit:ListBoxDragDropTarget HorizontalAlignment="Left"
                               HorizontalContentAlignment="Stretch"
                               VerticalAlignment="Top"
                               VerticalContentAlignment="Stretch"
                               Margin="39,117,0,0"
                               Grid.Row="1"
                               AllowDrop='True'>
  <ListBox x:Name='columnHeadings'
           MinHeight='100'
           MinWidth='100'>
  </ListBox>
</toolkit:ListBoxDragDropTarget>

<toolkit:ListBoxDragDropTarget AllowDrop='True'
                               Grid.Column='1'
                               Grid.Row='1'
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Left">
  <ListBox x:Name='customerFields'
           Grid.Column='1'
           Grid.Row='1'
           Visibility='Collapsed'
           Drop='CustomerFieldsDrop'>
  </ListBox>
</toolkit:ListBoxDragDropTarget>

コード ビハインド ページのイベント ハンドラーは次のとおりです。

private void CustomerFieldsDrop(object sender, DragEventArgs e)
{
  MessageBox.Show(string.Format("Something was dropped!"));
}

ご覧のとおり、私は本当にシンプルなものを目指していました。List Boxの親ListBoxDragDropTargetにイベント ハンドラーを割り当ててみました。customerFields皮肉なことに、それはうまくいきました。

ここでの目的は、ユーザーがテキスト ファイルをインポートして、ファイルの列ヘッダーのリストを 1 つのリスト ボックスに取得し、それらを 2 番目のリスト ボックスにリストされているデータ フィールドに「接続」できるようにすることです。そのため、リストの並べ替えや、あるリストから別のリストへのアイテムの移動はありません。

columnHeadings.ItemsSourceプロパティはオブジェクトstring[]です。customerFields.ItemsSourceプロパティはオブジェクトIEnumerable<string>です。

任意の洞察をいただければ幸いです。

4

1 に答える 1

0

AllowDrop="True" および Drop="EventName" プロパティが機能するには、同じ要素内にある必要があると思います。おそらく、ListBox 自体で AllowDrop プロパティを "True" に設定する必要があります。

<ListBox x:Name="customerFields" 
    Grid.Column="1" 
    Grid.Row="1" 
    Visibility="Collapsed"
    Drop="CustomerFieldsDrop"
    AllowDrop="True" 
</ListBox> 

または、Drop="CustomerFieldsDrop" プロパティを ListBoxDragDropTarget タグに追加します。

<toolkit:ListBoxDragDropTarget AllowDrop='True'   
    Grid.Column='1'   
    Grid.Row='1'   
    HorizontalContentAlignment="Stretch"   
    VerticalContentAlignment="Stretch"   
    VerticalAlignment="Center"   
    HorizontalAlignment="Left"
    Drop="CustomerFieldsDrop">

どちらかが動作するはずです...

于 2012-05-31T21:50:16.290 に答える