private void MoveItemClick(ItemCntr it, int i, int j) { blocks.setBlock(blocks.getBlock(it.I, it.J), i, j); blocks.setBlock(0, it.I, it.J); Storyboard sb = new Storyboard(); DoubleAnimation da = new DoubleAnimation(); if (i == it.I) { da.From = it.J * it.Width; da.By = j * it.Width - da.From; } else { da.From = it.I * it.Height; da.By = i * it.Height - da.From; } da.Duration = new Duration(TimeSpan.FromSeconds(.2)); sb.Children.Add(da); object prop = it.I == i ? Canvas.LeftProperty : Canvas.TopProperty; Storyboard.SetTargetProperty(da, new PropertyPath(prop)); sb.Begin(it, true); sb.Completed += new EventHandler(sb_Completed); it.I = i; it.J = j; }
private void DrawBoard() { cnBoard.Children.Clear(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (blocks.getBlock(i, j) > 0) { ItemCntr cnv = new ItemCntr { IntVal = blocks.getBlock(i, j), Width = cnBoard.Width / N, Height = cnBoard.Height / N, I = i, J = j }; Canvas.SetTop(cnv, i * cnBoard.Width / N); Canvas.SetLeft(cnv, j * cnBoard.Width / N); cnBoard.Children.Add(cnv); cnv.MouseLeftButtonUp += new MouseButtonEventHandler(cnv_MouseLeftButtonUp); } } } }