WPF 允许使用 Transform
缩放( ScaleTransform
), 旋转(RotateTransform
)、倾斜 (SkewTransform
)等任何 FrameworkElement
。
但我看不到如何裁剪一些 FrameworkElement
使用这些。有什么方法可以裁剪宽度为 30px 的 Label
,这样它的行为就像宽度为 20px 一样吗?
更准确地说:我想在布局之前执行此操作,以便 Label
的布局就像其宽度为 20 一样。但我希望它完全渲染,以便最后 10 个像素将也渲染(可能与其他元素重叠)。我该怎么做?
为什么我需要这个?我想对我的HB的答案问题 在 WPF 中创建吉他和弦编辑器以使用 字距调整。
WPF allows to use subclasses of Transform
to scale(ScaleTransform
), rotate(RotateTransform
), skew (SkewTransform
) and so on any FrameworkElement
.
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?
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 ?
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.
发布评论
评论(2)
在标签上使用负
Margin
,例如Margin="0,0,-10,0"
使标签在布局方面右侧短 10 像素。 (为了防止重叠,将其放入容器中并设置ClipToBounds="True"
)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 setClipToBounds="True"
)我对 HB 解决方案的问题是,我不能只绑定顶部边距。
我使用像这样的 XAML 来构建一种圆形进度条(一个椭圆形,在顶部被裁剪):
当我更改画布的高度时,椭圆的顶部被裁剪(因为它与画布的底部对齐) )。如果我将它对齐到顶部(默认),它将被裁剪在底部。
我在圆形图标内使用此构造来根据进度按比例填充它。
My problem with H.B.'s solution was, that i can't bind only the top margin.
i use XAML like this to build kindof a round progressbar (an ellipse, that gets cropped at the top):
When i change the height of the canvas, the top of the ellipse gets cropped (because it is aligned to the bottom of the canvas). if i aligned it to the top (default), it would be cropped on the bottom.
I use this construct inside a round icon to fill it up proportionaly to the progress.