WP中弹出层学习

来源:互联网 发布:www.js study.cn 编辑:程序博客网 时间:2024/05/16 09:03

最近在项目中有个功能是,当点击一个内容是电话号码的单元格时,弹出一个打电话的图像,当点击图像时调用系统的打电话的功能,弹出那个打电话的图像的实现思路是:新建一个Canvas,在这个画布中添加一个Popup控件,在这个Popup控件中加入一个Image控件,这个控件的图片路径是那个电话图片的路径

Image messagePhone = new Image();

  messagePhone.Source = new BitmapImage(new Uri("ImageResources/report.messagesend.png", UriKind.Relative));这里要注意Source属性的类型,

接下来把Popup的child属性设置成Image对象,在把Popup对象加入到Canvas中,在画布中添加一个事件,鼠标点击事件,在这个事件中我们要把Popup的Isopen属性设置为false,如果我们使用的代码New的Popup控件,注意这里要把它弄到类里面,如果是托的,就不用管了。

这是我写的部分代码

 Button btnPhone = new Button();
                Image imagePhone = new Image();
                //imagePhone.Stretch = Stretch.Fill;
                imagePhone.Source=new BitmapImage(new Uri("ImageResources/report.phonecall.png",UriKind.Relative));
                btnPhone.Content = imagePhone;
                btnPhone.Click += btnPhone_Click;
                Button btnMessage = new Button();
                Image messagePhone = new Image();
                messagePhone.Source = new BitmapImage(new Uri("ImageResources/report.messagesend.png", UriKind.Relative));
               // messagePhone.Stretch = Stretch.Fill;
                btnMessage.Content = messagePhone;
                btnMessage.Click += btnMessage_Click;
                StackPanel sp = new StackPanel();
                sp.Background = new SolidColorBrush(Colors.Blue);
                sp.Children.Add(btnPhone);
                sp.Children.Add(btnMessage);
                pop = new Popup();
                pop.Child = sp;
                pop.IsOpen = true;
                Canvas ca = new Canvas();
                ca.Children.Add(pop);
                ca.Background = new SolidColorBrush(Colors.Transparent);
                this.LayoutRoot.Children.Add(ca);
              

原创粉丝点击