我已将 Grid 的背景画笔设置为 ImageBrush。
但是当我将网格的 FlowDirection 设置为 RightToLeft 时,图像会水平翻转。
是否可以使用某种过渡或任何其他方式(取消)翻转网格背景 ImageBrush?
我已将 Grid 的背景画笔设置为 ImageBrush。
但是当我将网格的 FlowDirection 设置为 RightToLeft 时,图像会水平翻转。
是否可以使用某种过渡或任何其他方式(取消)翻转网格背景 ImageBrush?
用明智的手段你无能为力(同样的手段远非明智)。
而是使用 Grid.RowSpan、Grid.ColumnSpan 将 Image 元素作为 Grid 中的第一项来覆盖所有单元格。在图像上使用 Stretch="Fill",因为这就是背景通常的行为方式。
好吧,我明白我的评论已经过时了,但是这个问题在谷歌搜索中出现了第一个问题,所以这是我的解决方案:
我正在本地化从右到左文化的应用程序。设置 FlowDirection=RTL 的简单决定带来了意想不到的缺点,例如包含公司徽标的背景被翻转。我已经为用于渲染背景的图像画笔应用了矩阵变换:
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;