我有一个非常简单的问题,但我似乎把这个想法弄复杂了,也许有人可以指导我或者帮助我一点.
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="465" Width="681"> <Grid> <ListBox x:Name="listBox1" HorizontalAlignment="Left" Height="405" Margin="10,10,0" VerticalAlignment="Top" Width="208" MouseDown="listBox1_MouseDown"> <ListBoxItem Content="Gordon"/> <ListBoxItem Content="Nico"/> </ListBox> <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="405" Margin="289,0" textwrapping="Wrap" VerticalAlignment="Top" Width="364" SpellCheck.IsEnabled="True" Cursor="IBeam" AcceptsReturn="True" AllowDrop="True" dragenter="textBox1_dragenter"/> </Grid> </Window>
我在C#中的代码如下所示,这就是我被困的地方:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void listBox1_MouseDown(object sender,MouseButtonEventArgs e) { DragDrop.DoDragDrop(listBox1,listBox1.SelectedItem.ToString(),DragDropEffects.copy); } private void textBox1_dragenter(object sender,DragEventArgs e) { e.Effects = DragDropEffects.copy; } private void textBox1_PreviewDragOver(object sender,DragEventArgs e) { e.Handled = true; } } }
提前致谢.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。