2011-09-01 46 views
2

我已經將網格的背景刷子設置爲ImageBrush。
但是,當我將Grid的FlowDirection設置爲RightToLeft時,圖像會水平翻轉。翻轉水平網格背景圖像(刷子)

是否有可能使用某種過渡或其他方式(un)翻轉網格背景ImageBrush?

回答

0

哦,我明白,我的意見是過時的,但這個問題是突然出現在谷歌搜索的第一個,所以這裏是我的解決方案:

我被定位爲從右到應用離開文化。設置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; 
1

你可以用合理的方法做到這一點(這意味着遠遠不合理)。

取而代之的是使用Grid.RowSpan,Grid.ColumnSpan將一個Image元素作爲Grid中的第一項來覆蓋所有的單元格。因爲這就是後臺通常的表現,所以在圖像上使用Stretch =「Fill」。