开发者

WPF image thumbnail with the offset

I have an im开发者_开发知识库age 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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜