开发者

Flip Horizontically Grid Background Image(Brush)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜