如何设置绘制一个对话框,对话框随内容自适应宽度

复制代码
<Canvas>
        <TextBlock x:Name="stitchOverTopTextBlock"FontFamily="Microsoft YaHei" Text="好好学习 天天向上" 
           SizeChanged
="stitchOverTopTextBlock_SizeChanged" Panel.ZIndex="1" Foreground="#FFB711" FontSize="14"VerticalAlignment="Center" HorizontalAlignment="Center"/> <Path Stroke="#3D4B52" StrokeThickness="1"> <Path.Fill> <SolidColorBrush Color="#151E22" Opacity="0.7"/> </Path.Fill> <Path.Data> <PathGeometry> <PathFigure IsClosed="True" StartPoint="0,0"> <PathFigure.Segments> <LineSegment x:Name="P1" Point="0,0"/> <LineSegment x:Name="P2" Point="0,22"/> <LineSegment x:Name="P3" /> <LineSegment x:Name="P4" /> <LineSegment x:Name="P5" /> <LineSegment x:Name="P6" /> <LineSegment x:Name="P7" /> <LineSegment x:Name="P8" Point="0,0"/> </PathFigure.Segments> </PathFigure> </PathGeometry> </Path.Data> </Path> </Canvas>
复制代码

通过使用SizeChanged事件控制Path的形状:

复制代码
        private void stitchOverTopTextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            //绘制对话框
            P3.Point = new Point((stitchOverTopTextBlock.ActualWidth + 20) / 2 - 7, 22);
            P4.Point = new Point((stitchOverTopTextBlock.ActualWidth + 20) / 2, 29);
            P5.Point = new Point((stitchOverTopTextBlock.ActualWidth + 20) / 2 + 7, 22);
            P6.Point = new Point(stitchOverTopTextBlock.ActualWidth + 20, 22);
            P7.Point = new Point(stitchOverTopTextBlock.ActualWidth + 20, 0);
        }
复制代码

 

posted @   LXLR  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示