-------------------------------------------------------
public partial class MainWindow : Window
{
List
public MainWindow()
{
EvtList = new List
InitializeComponent();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
StackPanel stp = new StackPanel();
stp.Width = 80;
stp.Height = 80;
stp.AllowDrop = true;
stp.Background = Brushes.Transparent; // Here is very Important
Grid.SetColumn(stp, j);
Grid.SetRow(stp, i);
Image imgbox = new Image();
imgbox.Width = 80;
imgbox.Height = 80;
stp.Children.Add(imgbox);
EventClass evc = new EventClass(stp, lbl,imgbox, i, j);
EvtList.Add(evc);
stp.Drop += evc.DropEventMethod;
gridmain.Children.Add(stp);
}
}
}
-------------------------------------------------------
Class Code
-------------------------------------------------------
public class EventClass
{
public StackPanel Btn;
public Label Lbl;
public Image Img;
public int Rownum;
public int Colnum;
public EventClass(StackPanel btn, Label lbl , Image img,int row,int col)
{
Btn = btn;
Rownum = row;
Colnum = col;
Lbl = lbl;
Img = img;
}
public void DropEventMethod(object ss, DragEventArgs ee)
{
this.Lbl.Dispatcher.BeginInvoke((Action)(() => Lbl.Content = $"Click i = {this.Rownum} j = {this.Colnum}" ));
string[] files = (string[])ee.Data.GetData(DataFormats.FileDrop);
Lbl.Content = files[0];
Img.Source = new BitmapImage(new Uri(files[0]));
}
}
-------------------------------------------------------
Xaml Code
-------------------------------------------------------
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:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
댓글 없음:
댓글 쓰기