0

我正在为 Windows Phone 7 使用 C#、Silverlight、Visual Studio。

我想获得一个剪辑,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本身。

提前致谢。

4

1 回答 1

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;

我提到我在分配变量之前检查了对我的 UIElements 的一些限制。这与我发布的关于剪辑的另一个问题有关(此处)。

于 2012-10-29T14:16:23.037 回答