如何忽略形状填充对象的变换(Silverlight)?
我在 Silverlight 中有一个旋转 15 度的矩形。它充满了图像。 SL 的正常行为是使用其父对象(在本例中为矩形)旋转 Fill 对象。
有没有办法忽略填充对象的变换效果?我希望图像在屏幕上继续指向北。
下面是我的 XAML。我想看看是否有属性或其他方法可以不旋转 ImageBrush (image2.png)。
<Rectangle x:Name="Rectangle_5_ID6" RenderTransformOrigin="0.5 0.5" Height="24" Width="78" Stroke="#000000" StrokeThickness="1" Canvas.Top="25" Canvas.Left="25">
<Rectangle.RenderTransform>
<TransformGroup>
<RotateTransform Angle="15" />
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<ImageBrush ImageSource="image2.png" />
</Rectangle.Fill>
</Rectangle>
I have a Rectangle Shape in Silverlight that is rotated 15 degrees. It is filled with an image. The normal behavior of SL is to rotate the Fill object with it's parent (the rectangle, in this case).
Is there any way to ignore the transform effect for the Fill object? I'd like the image to continue to point north on the screen.
Here's the XAML I have below. I'd like to see if there is a property or another way to not rotate the ImageBrush (image2.png).
<Rectangle x:Name="Rectangle_5_ID6" RenderTransformOrigin="0.5 0.5" Height="24" Width="78" Stroke="#000000" StrokeThickness="1" Canvas.Top="25" Canvas.Left="25">
<Rectangle.RenderTransform>
<TransformGroup>
<RotateTransform Angle="15" />
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<ImageBrush ImageSource="image2.png" />
</Rectangle.Fill>
</Rectangle>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种不同的方法,但我怀疑最适合您需求的方法是使用
Path
代替。该路径最终有一个矩形区域,可以容纳其数据中包含的所有几何图形以及绘制到该区域中的填充。矩形几何体是通过应用旋转变换来绘制的,并且只有出现在几何体内部的填充部分实际上是可见的,其余部分被剪掉。因此你得到了想要的输出。
There are a number of different approaches but I suspect the one that fits your needs the best would be to use a
Path
instead.The path ends up having a rectangular area that can accommodate all the geometries contain in its data and the fill drawn into this area. The Rectangle geometry is drawn with the rotate transform applied and only the part of the fill that appears inside the geometry is actually visibile the rest is clipped. Hence you get the desired output.