2012-10-15 44 views
0

我使用C#,Silverlight中,Visual Studio中的Windows Phone 7轉化UIElement的剪輯

我想獲得一個UIElement,其中包括已經在UIElement做過任何改造的剪輯。

這個例子給我的剪輯,但不包括從UIElement的任何變換:

// uie is a UIElement taken from a PhoneApplicationPage 
Geometry myClip = uie.Clip; 

我嘗試以下,但它結束了移動UIElement

var frame = Application.Current.RootVisual as PhoneApplicationFrame; 
var page = frame.Content as PhoneApplicationPage; 
GeneralTransform gt = uie.TransformToVisual(page); 
uie.RenderTransform = gt as Transform; 
Geometry myClip = uie.Clip; 

我也嘗試過在結尾添加逆變換以撤銷任何移動,但這似乎使情況變得更糟:

uie.RenderTransform = gt.Inverse as Transform; 

請幫我把與原來的剪輯轉換UIElement,而不再與UIElement本身搞亂。

在此先感謝。

回答

0

我想通了,如何解決這個不會對原有的UIElement搞亂。我需要創建一個具有相同數據的新Geometry對象,而不是使用原始Geometry。這不僅從可能得到指定爲孩子多個對象分開的新數據從舊的數據,還可以防止一個對象。

這裏是生成的代碼我使用:

var frame = Application.Current.RootVisual as PhoneApplicationFrame; 
var page = frame.Content as PhoneApplicationPage; 
GeneralTransform gt = uie.TransformToVisual(page); 
var place = gt.Transform(new Point()); 
// declaring new variables to hold these values 
Geometry geom; 
Path path = new Path(); 
// here I checked for other restrictions on my UIElements before assigning the variables 
geom = new RectangleGeometry(); 
(geom as RectangleGeometry).Rect = new Rect(place.X, place.Y, uie.RenderSize.Width, uie.RenderSize.Height); 
path.Data = geom; 

我說過,我檢查分配變量之前對我的UI元素有一些限制。這與我發佈的關於剪輯的另一個問題有關(here)。