Ievgen
Ievgen

Reputation: 4443

WPF image thumbnail with the offset

I have an image 800x600 and I would show a thumbnail 90x30 with some offset x=12 and y 12.

I have created a brush but I am struggling to apply an offset.

 var source = new ImageBrush(groundSource);
                source.Stretch = Stretch.None;
                source.AlignmentX = AlignmentX.Left;
                source.AlignmentY = AlignmentY.Top;
                source.RelativeTransform = new TranslateTransform(0.5, 0);
                var grid = new Grid();
                grid.ClipToBounds = true;
                grid.Background = source;
                grid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                grid.Margin = new System.Windows.Thickness(12, 12, 0, 0);
                grid.Width = SpriteSize.SpriteWidht + 33;
                grid.Height = SpriteSize.SpriteHeight;
                grid.SnapsToDevicePixels = true;

I would appreciate any suggestions.

Upvotes: 1

Views: 2796

Answers (1)

Ievgen
Ievgen

Reputation: 4443

There is a hacky solution for this problem:

  • Add Image as a child to the Grid.
  • Set Grid attribute as ClipToBounds=true
  • Set Image margin to control thumbnail offset.

Upvotes: 5

Related Questions