裁剪变换在WPF?WPF

2023-09-06 22:13:39 作者:亡命男人

WPF允许使用 变换 规模(的 ScaleTransform ),旋转(的 RotateTransform ),歪斜(的 SkewTransform )等任何的 FrameworkElement的

WPF allows to use subclasses of Transform to scale(ScaleTransform), rotate(RotateTransform), skew (SkewTransform) and so on any FrameworkElement.

但我不能看到如何进行一些裁剪 FrameworkElement的 使用这些。有什么办法如何裁剪可以说的标签宽度30像素,因此将像它的宽度为20像素?

But I cannot see how to crop some FrameworkElement using these. Is there any way how to crop lets say a Label of width 30px so it will behave as if its width was 20px?

要更确切的说:我想这样做铺设之前,使标签将布局为如果它的宽度为20。但我希望它是呈现充分所以最后10个像素也将被渲染(可能是重叠的其他元素)。我怎样才能做到这一点?

To be more exact: I want to do this before laying out so that the Label would be laid out as if its width was 20. But I want it to be rendered fully so the last 10 pixels will be rendered too (possibly overlapping other elements). How can I do this ?

为什么我需要这个?我想打H.B.'s回答我的问题Create在WPF吉他和弦编辑,提供字距。

Why do I need this ? I want to make H.B.'s answer to my question Create guitar chords editor in WPF to work with kerning.

推荐答案

使用负保证金标签上,如保证金=0,0,-10,0使标签10像素右侧短,布局明智的。 (为prevent重叠把它放在一个容器中,并设置 ClipToBounds =真

Use a negative Margin on the label, e.g. Margin="0,0,-10,0" makes the Label 10 pixels shorter on the right, layout-wise. (To prevent overlap put it in a container and set ClipToBounds="True")