private void ReconstructGrid(Tileset tileset) { int width = 0; int height = 0; sheetImage.Source = null; // If we have tileset selected, we can reconstruct the grid. Else, just reset it. if (tileset != null) { // Reconstruct grid. string pathToImage = editor.GetTexturePath(tileset.Texture); BitmapImage image = ImageHelper.LoadToMemory(pathToImage); sheetImage.Source = image; // Calculate area size. width = tileset.SourceSize.X * tileset.IndicesCount.X; height = tileset.SourceSize.Y * tileset.IndicesCount.Y; } // Keep offset at zero, we don't want to move the grid but the image instead. tileGridManager.Reconstruct(width, height, tileset.SourceSize.X, tileset.SourceSize.Y, 0, 0); Canvas.SetLeft(sheetImage, -tileset.Offset.X); Canvas.SetTop(sheetImage, -tileset.Offset.Y); // Set view size. sheetCanvas.Width = width; sheetCanvas.Height = height; // Set border size. gridBorder.Width = width; gridBorder.Height = height; // Set image size. Adjust it to the size of the view. sheetImage.Width = Math.Min(width, sheetImage.Source.Width); sheetImage.Height = Math.Min(height, sheetImage.Source.Height); }