开发者

Crop transform in WPF?

开发者 https://www.devze.com 2023-03-01 06:54 出处:网络
WPF allows to use subclasses of Transform to scale(ScaleTransform), rotate(RotateTransform), skew (SkewTransform) and so on any FrameworkElement.

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 beh开发者_运维问答ave 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.


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")


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):

<Canvas Name="ProgressIndicator" Width="120" Height="{Binding ProgressIndicatorHeight}" ClipToBounds="True">
    <Ellipse Width="120" Canvas.Bottom="0" Height="120" Fill="#FF7090B7"/>
</Canvas>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号