Example #1
0
        private static void PopulateCanvas(Canvas canvas, List <CustomImage> images, bool needsExtraRoom)
        {
            var extraRoom = needsExtraRoom ? 10 : 0;

            canvas.Children.Clear();
            foreach (var graphic in images)
            {
                canvas.Children.Add(graphic);
            }

            foreach (UIElement child in canvas.Children)
            {
                if (child is CustomImage temp)
                {
                    Canvas.SetLeft(child, temp.InCanvasPosition.X);
                    Canvas.SetTop(child, temp.InCanvasPosition.Y);
                }
            }

            var contentBounds = ImageExtensions.GetMaxSizeInList(images);

            if (contentBounds.X > contentBounds.Y)
            {
                canvas.Width  = contentBounds.X + extraRoom;
                canvas.Height = contentBounds.X + extraRoom;
            }
            else
            {
                canvas.Width  = contentBounds.Y + extraRoom;
                canvas.Height = contentBounds.Y + extraRoom;
            }

            try
            {
                canvas.RenderSize = new System.Windows.Size(canvas.Width, canvas.Height);
                canvas.Background = (SolidColorBrush)Application.Current.Resources["LightSpaceGray"];
            }
            catch (Exception)
            {
                // On application shutdown sometimes it will finish calling rendering functions while the application itself is already unavailable.
                // This results in a NullReferenceException.
            }
        }
Example #2
0
        private static void PopulateCanvas(Canvas canvas, List <List <CustomImage> > images)
        {
            canvas.Children.Clear();
            foreach (var graphic in images.SelectMany(imageList => imageList))
            {
                canvas.Children.Add(graphic);
            }

            foreach (UIElement child in canvas.Children)
            {
                if (child is CustomImage temp)
                {
                    Canvas.SetLeft(child, temp.InCanvasPosition.X * 14);
                    Canvas.SetTop(child, temp.InCanvasPosition.Y * 14);
                }
            }

            var contentBounds = Vector2.Zero();

            foreach (var list in images)
            {
                contentBounds.MapHighestValue(ImageExtensions.GetMaxSizeInList(list));
            }

            if (contentBounds.X > contentBounds.Y)
            {
                canvas.Width  = contentBounds.X * images.Count;
                canvas.Height = contentBounds.X * images.Count;
            }
            else
            {
                canvas.Width  = contentBounds.Y * images[0].Count;
                canvas.Height = contentBounds.Y * images[0].Count;
            }
            canvas.RenderSize = new System.Windows.Size(canvas.Width, canvas.Height);
            canvas.Background = (SolidColorBrush)Application.Current.Resources["LightSpaceGray"];
        }