2011-01-31 59 views
2

我想通過兩個三角形非常簡單的任務來繪製矩形,但是Silverlight可以不處理它Silverlight的 - 。史詩圖形失敗(由兩個三角形矩形):(

<Grid x:Name="LayoutRoot" UseLayoutRounding="False" Background="White"> 
    <Polygon Fill="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="100"/> 
      <Point X="100" Y="10"/> 
      <Point X="100" Y="100"/> 
     </Polygon.Points> 
    </Polygon> 
    <Polygon Fill="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="10"/> 
      <Point X="100" Y="10"/> 
      <Point X="10" Y="100"/> 
     </Polygon.Points> 
    </Polygon> 

</Grid> 

Logicly我還得看矩形當我編譯這個代碼。如果你嘗試使用這個代碼,你會看到矩形,但你會有一個annoing白線在它...

所以我想知道..有沒有辦法繪製矩形(看起來像矩形)由Silverlight中的兩個三角形組成?

回答

3

這是在XAML有點冗長,但如果你編程創建三角形它不應該的問題,怎麼樣像這樣:

<Canvas Background="#FFF9B15A" Width="200" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left"> 
    <Path Fill="Black" StrokeThickness="0"> 
     <Path.Data> 
      <GeometryGroup> 
       <PathGeometry> 
        <PathGeometry.Figures> 
         <PathFigureCollection> 
          <PathFigure IsClosed="True" StartPoint="10,10"> 
           <PathFigure.Segments> 
            <PathSegmentCollection> 
             <LineSegment Point="100,10" /> 
             <LineSegment Point="10, 100" /> 
            </PathSegmentCollection> 
           </PathFigure.Segments> 
          </PathFigure> 
         </PathFigureCollection> 
        </PathGeometry.Figures> 
       </PathGeometry> 
       <PathGeometry> 
        <PathGeometry.Figures> 
         <PathFigureCollection> 
          <PathFigure IsClosed="True" StartPoint="10,100"> 
           <PathFigure.Segments> 
            <PathSegmentCollection> 
             <LineSegment Point="100,10" /> 
             <LineSegment Point="100, 100" /> 
            </PathSegmentCollection> 
           </PathFigure.Segments> 
          </PathFigure> 
         </PathFigureCollection> 
        </PathGeometry.Figures> 
       </PathGeometry> 
      </GeometryGroup> 
     </Path.Data>  
    </Path> 
</Canvas> 

這樣,你真的合成一個單一的元素,路徑,三角形。你顯示的方式創建了單獨的元素,每個元素都將被單獨消除鋸齒。

希望有所幫助。

Sergio

2

你是否檢查過StrokeStrokeThickness屬性?我不確定它們是否具有默認值,這將允許您在三角形之間沒有任何空間的情況下繪製矩形。

UPDATE 這會幫助你嗎?

<Grid x:Name="LayoutRoot" UseLayoutRounding="False" Background="White"> 
    <Polygon Fill="Black" Stroke="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="100"/> 
      <Point X="100" Y="10"/> 
      <Point X="100" Y="100"/> 
     </Polygon.Points> 
    </Polygon> 
    <Polygon Fill="Black" Stroke="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="10"/> 
      <Point X="10" Y="100"/> 
      <Point X="100" Y="10"/> 
     </Polygon.Points> 
    </Polygon> 
</Grid> 
+0

您是否在此代碼中看到過我設置了Stroke或StrokeThickness?那麼這意味着我使用這個屬性的默認值。只是試試這個代碼.. – 2011-01-31 18:15:47

+0

@Ai_boy:更新回答 – Snowbear 2011-02-01 13:20:04

+0

它有幫助,但這不是我所期待的。我不想使用Stroke屬性... – 2011-02-01 20:06:42

1

將.5添加到連接側的點上。 Silverlight關於邊緣有點奇怪。看看矩形的邊緣,看它們是灰色還是純黑色。你可能不得不調整一些.5's來解決這個問題。

<Grid x:Name="LayoutRoot" UseLayoutRounding="False" Background="White"> 
    <Polygon Fill="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="100"/> 
      <Point X="100" Y="10"/> 
      <Point X="100" Y="100"/> 
     </Polygon.Points> 
    </Polygon> 
    <Polygon Fill="Black"> 
     <Polygon.Points> 
      <Point X="10" Y="10"/> 
      <Point X="100.5" Y="10.5"/> 
      <Point X="10.5" Y="100.5"/> 
     </Polygon.Points> 
    </Polygon> 

</Grid>