当前位置:网站首页 / WPF / 正文

ay wpf 写一个真圆角的UIElement

时间:2022年11月30日 | 作者 : aaronyang | 分类 : WPF | 浏览: 675次 | 评论 0

我写了一个demo

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp5"
        xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="WpfApp5.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Border	Name="myBorder" CornerRadius="40" Background="White" Margin="1"/>

        <ListBox Background="AntiqueWhite" Width="300" Height="200" >
            <ListBox.OpacityMask>
                <VisualBrush Visual="{Binding ElementName=myBorder}"/>
            </ListBox.OpacityMask>
            <ListBoxItem Content="11111112121"/>
            <ListBoxItem Content="33434343sdfdf dfd "/>
            <ListBoxItem Content="11111112121"/>
            <ListBoxItem Content="33434343sdfdf dfd "/>
        </ListBox>
    </Grid>
</Window>

效果:

image.png

如果知道具体的大小,还可以这样写

myImage.Clip = new RectangleGeometry(new Rect(0, 0, 400, 267), 40, 40);


你也可以组合

<Canvas >
            <Canvas.Clip>
                <CombinedGeometry GeometryCombineMode="Exclude">
                    <CombinedGeometry.Geometry1>
                        <GeometryGroup FillRule="Nonzero">
                            <RectangleGeometry Rect="100 100 100 100" />
                        </GeometryGroup>
                    </CombinedGeometry.Geometry1>
                    <CombinedGeometry.Geometry2>
                        <GeometryGroup FillRule="Nonzero">
                            <RectangleGeometry Rect="150 100 500 500"  />
                        </GeometryGroup>
                    </CombinedGeometry.Geometry2>
                </CombinedGeometry>
            </Canvas.Clip>     
        </Canvas>


====================www.ayjs.net       杨洋    wpfui.com        ayui      ay  aaronyang=======请不要转载谢谢了。=========

目前 按照OpacityMask能满足我的需求





推荐您阅读更多有关于“wpf,”的文章

猜你喜欢

额 本文暂时没人评论 来添加一个吧

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

  查看权限

抖音:wpfui 工作wpf

目前在合肥企迈科技公司上班,加我QQ私聊

2023年11月网站停运,将搬到CSDN上

AYUI8全源码 Github地址:前往获取

杨洋(AaronYang简称AY,安徽六安人)AY唯一QQ:875556003和AY交流

高中学历,2010年开始web开发,2015年1月17日开始学习WPF

声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费

查看捐赠

AYUI7.X MVC教程 更新如下:

第一课 第二课 程序加密教程

标签列表