WPF - 在画布内剪切 ContentControl
我有一个 ContentControl,其内容是自定义 FrameworkElement。 FrameworkElement 只有一个子元素,它是一个 DrawingVisual。基本上,ContentControl 是 DrawingVisual(包含形状)的容器,ContentControl 具有用户用来拖动、调整大小、旋转控件的拇指。 ContentControl被添加到Canvas上来显示。我想将 ContentControl 的剪切区域设置为 Canvas 中的特定区域。但是,当我将 ContentControl 的 Clip 属性设置为此区域(在 Canvas 坐标系中指定的 RectangleGeometry)时,ContentControl 内的 DrawingVisual 将被剪切,就好像给定区域位于 ContentControl 的坐标系中一样。
我可以限制用户仅在该区域内拖动,但我不想这样做。我希望用户能够将内容拖动到外部,并且当 ContentControl 的一部分位于外部时,我不希望渲染该部分。我该怎么做?
I have a ContentControl and its content is a custom FrameworkElement. FrameworkElement has only one child and it is a DrawingVisual. Basicly the ContentControl is a container for the DrawingVisual(which contains shapes) and ContentControl has the thumbs that the user use to drag, resize, rotate the control. ContentControl is added to a Canvas to display. I want to set clipping region of the ContentControl to a specific region in the Canvas. However when I set the Clip property of ContentControl to this region(RectangleGeometry specified in Canvas coordinate system) the DrawingVisual inside the ContentControl is clipped as if the given region is in the coordinate system of the ContentControl.
I can constrain the user to drag only inside this region but i don't want to do that. I want the user to be able drag outside and when a part of ContentControl is outside I don't want that part to be rendered. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在画布中创建一个中间内容控件,将其放置在您想要剪辑的位置,在其上设置cliptobounds = true,将现有的内容控件放入其中。
create an intermediate contentcontrol in the canvas, position this to be where you want things to clip, set cliptobounds=true on it, put your existing contentcontrol inside of it.