2011-07-08 106 views
2

請注意,在代碼中,我沒有在網格上放置任何剪輯,爲什麼顯示的這個矩形被剪裁爲網格的大小。爲什麼會發生此剪輯

我添加了偏移量,以顯示即使我將其移動到一邊網格的填充不是紅色。

<Grid Height="135" Width="162"> 
     <Rectangle Width="300" Height="249" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#FFDB1919" UseLayoutRounding="False"> 
      <Rectangle.Projection> 
       <PlaneProjection LocalOffsetX="-42"/> 
      </Rectangle.Projection> 

     </Rectangle> 
    </Grid> 

回答

2

電網具有的內容對默認的剪切。

最快的解決辦法是放在畫布的矩形(默認情況下沒有裁剪):

<Grid Height="135" Width="162"> 
    <Canvas> 
     <Rectangle Width="300" Height="249" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#FFDB1919" UseLayoutRounding="False" StrokeThickness="5"> 
      <Rectangle.Projection> 
       <PlaneProjection LocalOffsetX="-42"/> 
      </Rectangle.Projection> 
     </Rectangle> 
    </Canvas> 
</Grid> 

enter image description here

1

這就是發生在這裏:

 
1. WPF layout is done. it will place the 
    rectangle in the center as it was specified. 
2. The rectangle will be clipped by the Grid. 
3. The Projection transformation is applied after all this stuff. 
    In your case you did move already clipped rectangle by -42 pixels 
+0

爲什麼裁剪?如果我希望網格剪輯其內容,可以設置一個屬性,稱爲剪輯,爲什麼剪輯時不設置該屬性。換句話說,我能做些什麼,它不應該剪裁矩形,讓自由地顯示適合全寬? –

+0

正常情況下,剪切是網格的必要條件,這就是爲什麼它是默認行爲。你的問題不是你使用Projection的問題。在正常情況下,你不應該修改這個東西。如果你想在網格外部有一個矩形,你需要使用不同的方法。 – Sasha

+0

還有其他什麼方法? –