有一个有4行4列的网格,图像是(0,0)。现在我想把这张图片拖到网格的其他单元格中。请参阅以下代码
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Grid g = new Grid();
g.Height = 200;
g.Width = 200;
g.AllowDrop = true;
for (int i = 0; i < 4; i++)
{
RowDefinition row1 = new RowDefinition();
row1.Height = new GridLength(1, GridUnitType.Star);
g.RowDefinitions.Add(row1);
}
for (int i = 0; i < 4; i++)
{
ColumnDefinition col1 = new ColumnDefinition();
col1.Width = new GridLength(1, GridUnitType.Star);
g.ColumnDefinitions.Add(col1);
}
g.ShowGridLines = true;
this.Content = g;
**g.DragEnter +=new DragEventHandler(g_DragEnter);
g.DragLeave +=new DragEventHandler(g_DragLeave);**
Image im = new Image();
Uri ur = new Uri("im.bmp");
BitmapImage b = new BitmapImage(ur);
im.Source = b;
g.Children.Add(im);
}
public void g_DragEnter(object sender, DragEventArgs e)
{
}
public void g_DragLeave(object sender, DragEventArgs e)
{
}
}
我添加了两个事件:DragEnter和DragLeave到网格。但是这些事件没有被解雇,而且这段代码无法正常工作。
请帮助我编写适当的事件,说明如何将图像从一个单元格拖动到另一个单元格