private bool MoveTile(CloudsdaleItem cloud, int index) { var tile = tiles.FirstOrDefault(control => ((Cloud)control.Content).id == cloud.id); if (tile == null) return false; if (isDragging && draggingItem != null && tile.DataContext == draggingItem.DataContext) return true; var x = (index % 2 == 0) ? 5 : 185; var y = Math.Floor(index / 2.0) * 180; var leftAnimation = new DoubleAnimation { From = Canvas.GetLeft(tile), To = x, Duration = new Duration(TimeSpan.FromMilliseconds(100)), }; var topAnimation = new DoubleAnimation { From = Canvas.GetTop(tile), To = y, Duration = new Duration(TimeSpan.FromMilliseconds(100)), }; var storyboard = new Storyboard(); storyboard.Children.Add(leftAnimation); storyboard.Children.Add(topAnimation); Storyboard.SetTarget(leftAnimation, tile); Storyboard.SetTarget(topAnimation, tile); Storyboard.SetTargetProperty(leftAnimation, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTargetProperty(topAnimation, new PropertyPath(Canvas.TopProperty)); Resources.Add(Guid.NewGuid().ToString(), storyboard); storyboard.Begin(); return true; }
private void CreateTile(CloudsdaleItem cloud, int index) { if (MoveTile(cloud, index)) return; var control = new ContentPresenter { ContentTemplate = ItemTemplate, Content = cloud }; Canvas.SetLeft(control, (index % 2 == 0) ? 5 : 185); Canvas.SetTop(control, Math.Floor(index / 2.0) * 180); TileCanvas.Children.Add(control); tiles.Add(control); LayoutRoot.Height = Math.Ceiling(tiles.Count / 2.0) * 180; }