2013-04-25 18 views
0

我有一個Grid & Star形狀Path
在silverlight c#中如何將網格剪成星型路徑的形狀?

<Path x:Name="StarPath" Data="M213,135 L183,213 L87,246 L159,288 C159,288 140,372 140,375 C140,378 226,329 226,329 L303,367 L280,275 L316,216 L246,219" Fill="#FF0EB679" HorizontalAlignment="Left" Height="241.132" Margin="86.5,134.5,0,0" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" VerticalAlignment="Top" Width="230"/> 
<Grid HorizontalAlignment="Left" Height="300" Width="300" Background="#FFD11010"/> <br/><br/> 

我想讓我的Grid in the shape of Star shaped Path
任何人都可以提供任何提示或樣本Clipping Grid by Path by Code

+0

http://www.c-sharpcorner.com/uploadfile/mahesh/cropping-or-clipping-in-silverlight/這顯示瞭如何使用XAML形狀;如果你想用C#代碼來做,你可以訪問'UIElement.Clip'屬性並在那裏執行。 – 2013-04-25 15:24:43

+0

@ChrisSinclair謝謝。但是我正在尋找Path的剪輯;如果你能給我提供一個示例代碼片段(剪裁UIElement By Path),可能會感激不盡。 – asitis 2013-04-26 05:27:17

回答

0

你可以儘量去適應this méthod ...

MyGrid.Clip = getPathGeometry(StarPath.Data.ToString());

您必須添加 「||」在如果測試,並更改數據。更換data = data.Replace("M", " M").Replace("C", " C").Replace("L", " L");

+0

我試過了;但仍然有錯誤「」錯誤\t無法隱式地將類型'Windows.UI.Xaml.Media.PathGeometry'轉換爲'Windows.UI.Xaml.Media.RectangleGeometry'「。請注意,我正在使用Silverlight for windows phone。 – asitis 2013-04-26 12:03:48

+0

'PathGeometry'是'Geometry'的類型,如果我閱讀doc: PathGeometry =>受支持:Windows Phone OS 7.1,Windows Phone OS 7.0 ...(http://msdn.microsoft.com/fr-fr/library/ system.windows.media.pathgeometry(v = vs.95).aspx)。「Clip」的類型是什麼? – Tonio 2013-05-02 14:06:03