如何在ListBox拖放上获取selectedItem

时间:2014-09-23 12:46:45

标签: c# .net wpf silverlight listbox

我正在使用silverlight5 usinbg xaml,我必须将项目从1个ListBox拖放到另一个ListBox。

<ScrollViewer Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" HorizontalAlignment="Center" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Style="{StaticResource MP_ScrollViewerStyle}" BorderBrush="{x:Null}">
    <toolKit:ListBoxDragDropTarget AllowDrop="True" Grid.Row="1" Grid.Column="0">
        <ListBox x:Name="GroupFunctionListBox" Width="200" Height="Auto" SelectionMode="Extended" ItemsSource="{Binding GroupFunctionList}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="White" Background="{StaticResource BGBrush_1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Name="txt2" Text="{Binding Label}" Style="{Binding IsInGroup, Converter={StaticResource StyleFunctionConverter}}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </toolKit:ListBoxDragDropTarget>
</ScrollViewer>

<ScrollViewer Grid.Row="1" Grid.Column="2" Margin="5,5,5,5" HorizontalAlignment="Center" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Style="{StaticResource MP_ScrollViewerStyle}" BorderBrush="{x:Null}">
    <toolKit:ListBoxDragDropTarget AllowDrop="True" Grid.Row="1" Grid.Column="2">
        <ListBox x:Name="OtherFunctionListBox" Width="200" HorizontalAlignment="Center" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="Auto" SelectionMode="Extended" ItemsSource="{Binding OtherFunctionList}" Foreground="White" Background="{StaticResource BGBrush_1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Name="txt1" Text="{Binding Label}" Style="{Binding IsInGroup, Converter={StaticResource StyleFunctionConverter}}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </toolKit:ListBoxDragDropTarget>
</ScrollViewer>

正如您所看到的,ListBx都在ScrollView中,并且每个都包含一些文本块(写入文本字符串),这些文本块将被放在另一个ListBox上。 直到它正常工作,因为我已经完成了AllowDrop =&#34; True&#34; 但现在我想要手动删除另一个列表中的textbock字符串。

我知道我必须添加一些事件谎言"Drop="ListBoxDragDropTarget_Drop"

<toolKit:ListBoxDragDropTarget AllowDrop="False"  Grid.Row="1" Grid.Column="2"  Drop="ListBoxDragDropTarget_Drop">

并像这样处理:

 private void ListBoxDragDropTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e) 
{
    //What should i do to change the text of dragged textblock in LisBox to make it "Italic" ?
}

如果我想更改此事件中删除的TextBlock.Text属性的文本是否正确,请更正我?如何删除删除的TextBlock文本(提醒:拖动的TextBlock被删除/从第一个ListBox拖动并添加/删除到第二个ListBox,并改变Tect属性(Italic))。怎么做?

0 个答案:

没有答案