WPF Popup弹出框箭头自动定位效果

2021-01-31 01:14

阅读:517

标签:fse   binding   csharp   closed   pop   reg   代码   win   block   

在WPF中如何做到,点击按钮,弹出一个带箭头的消息框,箭头对准按钮,效果如图所示。

技术图片

 

 XAML代码

        
        ^123456789abcdefghijklmnopqrstuvw

  CS代码

        public MainWindow()
        {
            InitializeComponent();
            Popup1.Opened += Popup1_Opened;
            Popup1.Closed += Popup1_Closed;
        }

        private void Popup1_Closed(object sender, EventArgs e)
        {
            TextBlock1.SetValue(Canvas.LeftProperty, (double)0);
        }

        private void Popup1_Opened(object sender, EventArgs e)
        {
            Point point = button.TranslatePoint(new Point(0, 0), this);
            Point point2 = TextBlock1.TranslatePoint(new Point(0, 0), this);
            TextBlock1.SetValue(Canvas.LeftProperty, point.X - point2.X);
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            Popup1.IsOpen = true;
        }

  看代码其实很简单,只是没想到办法,突然想到了就写一个简单的例子做演示。

WPF Popup弹出框箭头自动定位效果

标签:fse   binding   csharp   closed   pop   reg   代码   win   block   

原文地址:https://www.cnblogs.com/chengNet/p/11632675.html


评论


亲,登录后才可以留言!