如何设置绘制一个对话框,对话框随内容自适应宽度
<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); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!