Negative Margin in WPF

荒凉一梦 提交于 2019-12-24 04:44:11

问题


When I set margin edges negative values, I want them still be inside the parent panel, but to cropped with parent border. This is What i have:

and this is what I want (made in paint):

My XAML:

    <Grid HorizontalAlignment="Left" Height="97" Margin="113,60,0,0" VerticalAlignment="Top" Width="125" Background="#FFF97C7C">
        <Ellipse Fill="#FFF4F5F4" Height="56" Margin="-48,-22,-46,63" Stroke="Black"/>
    </Grid>

How can I do it?


回答1:


Use ClipToBounds:

<Grid ClipToBounds="True" HorizontalAlignment="Left" Height="97" Margin="113,60,0,0" VerticalAlignment="Top" Width="125" Background="#FFF97C7C">
    <Ellipse Fill="#FFF4F5F4" Height="56" Margin="-48,-22,-46,63" Stroke="Black"/>
</Grid>

Result:



来源:https://stackoverflow.com/questions/31761307/negative-margin-in-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!