我正在使用C#,Silverlight,Visual Studio for Windows phone7。
我想得到一个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的原始转换剪辑。
提前谢谢。
发布于 2012-10-29 22:16:23
我想出了如何在不扰乱原始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;我提到过,在赋值变量之前,我会检查UIElements上的一些限制。这与我发布的另一个关于剪辑的问题(here)有关。
https://stackoverflow.com/questions/12899006
复制相似问题