开发者

Flip Horizontically Grid Background Image(Brush)

开发者 https://www.devze.com 2023-04-01 16:57 出处:网络
I have set a Grid\'s background brush as an ImageBrush. But when I set the Grid\'s FlowDirection to RightToLeft, the image is flipped horizontically.

I have set a Grid's background brush as an ImageBrush.

But when I set the Grid's FlowDirection to RightToLeft, the image is flipped horizontically.

Is it possible to (un)flip the grid background ImageBrush开发者_开发问答 using a certain Transition or any other way?


Not much you can do about that with sensible means (there same means that are far from sensible).

Instead place an Image element as the first item in the Grid with Grid.RowSpan, Grid.ColumnSpan to cover all the cells. Use Stretch="Fill" on the Image since thats how a background typically behaves.


Well, i do understand that my comment is outdated, but this question is popping up one of the first in Google search, so here is my solution:

I was localizing the application for the right-to-left culture. The simple decision to set FlowDirection=RTL comes with unexpected drawbacks like the background containing the company logo is flipped. I have applied the matrix transformation for the image brush used to render the background:

var mbgBrush = TryFindResource("MainBackground") as Brush;
        if (mbgBrush == null) return null;
        if (FlowDirection == FlowDirection.LeftToRight) return mbgBrush;
        var mainBgImageBrush = mbgBrush as ImageBrush;
        if (mainBgImageBrush == null) return mbgBrush;
        var flipXaxis = new MatrixTransform(-1.0, 0, 0, 1.0, 1, 0);
        var flippedBrush = new ImageBrush
                           {
                               Stretch = Stretch.None,
                               Opacity = 1.0,
                               ImageSource = mainBgImageBrush.ImageSource,
                               RelativeTransform = flipXaxis
                           };
        return flippedBrush;
0

精彩评论

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