使用路径剪切画布 [英] Clipping the canvas with the path

查看:109
本文介绍了使用路径剪切画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我创建了一个按钮模板,它呈现一个三角形按钮。该模板包含放置在画布中的许多路径项。当用户单击该按钮时,将启动一个动画,除了其他内容之外,还会旋转其中一个路径。问题是,当路径旋转时,它的一部分会查看按钮的边界。在画布上设置ClipToBound =true没有帮助,因为按钮是一个triange而画布不是。我的问题是:如何将Canvas.Clip属性设置为定义按钮外边框的Path? - 类似于:



< Canvas> 
< Canvas.Clip>
<路径宽度= 30高度= 30数据= ...... />
< / Canvas.Clip >
< / 画布 >





我们将不胜感激。



Uros

解决方案

答案非常简单:创建 Geometry 的实例并将其分配给属性 Canvas.Clip http: //msdn.microsoft.com/en-us/library/system.windows.uielement.clip.aspx [ ^ ]。



只有你必须这样做在代码中,我猜几何体应该在运行时修改。



-SA

Hi
I created a button template which renders a triangle button. The template contains a number of path items placed within the canvas. When the user clicks the button, an animation is started which, beside other things, rotates one of the paths. The problem is that when the path is rotated parts of it look over the bounds of the button. Setting the ClipToBound="true" on a canvas does not help since the button is a triange and the canvas is not. My question is: How can I set the Canvas.Clip property to a Path which defines the outer border of my button? - something like:

<Canvas>
   <Canvas.Clip>
      <Path Width="30" Height="30" Data="..." />
   </Canvas.Clip>
</Canvas>



Any idea will be appreciated.

Uros

解决方案

The answer is pretty straightforward: create your instance of Geometry and assign it to the property Canvas.Clip: http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip.aspx[^].

Only you have to do it in code, as I guess the geometry is supposed to be modified during run time.

—SA


这篇关于使用路径剪切画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆