博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Creating popup windows in XBAP applications
阅读量:5091 次
发布时间:2019-06-13

本文共 1774 字,大约阅读时间需要 5 分钟。

A colleague at  recently asked me about creating popup windows in XAML browser applications (XBAP). Normally this is not allowed – if you try to create a top-level window you will get a SecurityException because WPF asks forUIPermission which is strictly prohibited when hosted in the browser.

It turns out, however, that you can get a popup window – there’s a hidden little gem in theSystem.Windows.Controls.Primitive namespace that is your friend: Popup.

It’s the same underlying class that ToolTip, Menu, and ComboBox use to display drop-down menus and overlays and it is browser-hosting aware! It’s pretty limited in functionality – I’m not sure you can get it to move around with the mouse for example, but for simple cases it works great. Here’s a code snippet – wire this up to a button in an XBAP:

 

void OnClick(object sender, EventArgs e){    Popup window = new Popup();       StackPanel sp = new StackPanel { Margin = new Thickness(5) };    sp.Children.Add(new TextBlock { Text = "Hi from a popup" });    Button newButton = new Button { Content = "Another button" };    newButton.Click += delegate { window.IsOpen = false; };    sp.Children.Add(newButton);    sp.Children.Add(new Slider { Minimum = 0, Maximum = 50, Value = 25, Width = 100 });       window.Child = new Border { Background = Brushes.White, BorderBrush = Brushes.Black,                                      BorderThickness = new Thickness(2), Child = sp };    window.PlacementTarget = this;    window.Placement = PlacementMode.Center;       window.IsOpen = true; }

The key thing you need to do is set the PlacementTarget. That associates a “parent” window and without it, the Popup class asserts UIPermission which will fail in the browser environment.

转载于:https://www.cnblogs.com/zjoch/p/5084725.html

你可能感兴趣的文章
重启rabbitmq服务
查看>>
正则表达式(进阶篇)
查看>>
无人值守安装linux系统
查看>>
【传道】中国首部淘宝卖家演讲公开课:农业本该如此
查看>>
jQuery应用 代码片段
查看>>
MVC+Servlet+mysql+jsp读取数据库信息
查看>>
黑马程序员——2 注释
查看>>
用OGRE1.74搭建游戏框架(三)--加入人物控制和场景
查看>>
转化课-计算机基础及上网过程
查看>>
android dialog使用自定义布局 设置窗体大小位置
查看>>
ionic2+ 基础
查看>>
互联网模式下我们更加应该“专注”
查看>>
myeclipse集成jdk、tomcat8、maven、svn
查看>>
查询消除重复行
查看>>
Win 10 文件浏览器无法打开
查看>>
[leetcode]Minimum Path Sum
查看>>
内存管理 浅析 内存管理/内存优化技巧
查看>>
【BZOJ 5222】[Lydsy2017省队十连测]怪题
查看>>
Java跟Javac,package与import
查看>>
day-12 python实现简单线性回归和多元线性回归算法
查看>>