Creating popup windows in XBAP applications
A colleague at DevelopMentor 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() };
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 = , Maximum = , Value = , Width = }); window.Child = new Border { Background = Brushes.White, BorderBrush = Brushes.Black,
BorderThickness = new Thickness(), 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.
Creating popup windows in XBAP applications的更多相关文章
- Creating Dialogbased Windows Application (4) / 创建基于对话框的Windows应用程序(四)Edit Control、Combo Box的应用、Unicode转ANSI、Open File Dialog、文件读取、可变参数、文本框自动滚动 / VC++, Windows
创建基于对话框的Windows应用程序(四)—— Edit Control.Combo Box的应用.Unicode转ANSI.Open File Dialog.文件读取.可变参数.自动滚动 之前的介 ...
- Creating Dialogbased Windows Application (3) / 创建基于对话框的Windows应用程序(三)Checkbox的应用、窗体置顶、设置图标 / VC++, Windows
创建基于对话框的Windows应用程序(三) —— Checkbox的应用.窗体置顶.设置图标 上一节创建的窗体应用程序中,我们用到了Button和StaticText这两个控件.这一节中我们将学习使 ...
- Creating Dialogbased Windows Application (2) / 创建基于对话框的Windows应用程序(二)Button的应用、新建子窗体 / VC++, Windows
创建基于对话框的Windows应用程序(二) —— Button的应用.新建子窗体 可以发现上一节创建的窗体中,点击OK和Cancel两个按钮是没有任何反应的.现在我们来为他们添加退出对话框的功能. ...
- Creating Dialogbased Windows Application (1) / 创建基于对话框的Windows应用程序(一)新建窗体 / VC++, Windows
创建基于对话框的Windows应用程序(一) —— 新建窗体 1.新建一个Visual C++的Empty Project. 2.在Solution Explorer中右键Add New Item, ...
- System Operations on AWS - Lab 1W - Creating EC2 (Windows)
1. 创建CommandHost实例,登录到CommandHost,通过AWS CLI创建WebServer实例. 1.1 为CommandHost实例创建一个IAM角色 1.2 创建CommandH ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- Receive Windows Messages In Your Custom Delphi Class - NonWindowed Control - AllocateHWnd
http://delphi.about.com/od/windowsshellapi/a/receive-windows-messages-in-custom-delphi-class-nonwind ...
- windows消息处理(强烈推荐,收藏)
由于看了一下,比较好理解,暂时先放到这里,待有空再翻译.只是在每节后大致介绍一下讲的内容. 感觉写的比较全,无论从消息的原理还是从MFC操作上来说,值得一看,我也在此做个收藏. (一) 说明:以下首先 ...
- Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Services
本文内容为转载,供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Servi ...
随机推荐
- va_start(),va_end()函数应用【转】
转自:http://www.cnblogs.com/gogly/articles/2416833.html 原理解释: VA_LIST 是在C语言中解决变参问题的一组宏,在<stdarg.h&g ...
- 高可用的MongoDB集群【转】
刚接触MongoDB,就要用到它的集群,只能硬着头皮短时间去看文档和尝试自行搭建.迁移历史数据更是让人恼火,近100G的数据文件,导入.清理垃圾数据执行的速度蜗牛一样的慢.趁着这个时间,把这几天关于M ...
- [golang note] 环境搭建
LiteIDE(windows) • golang安装 ▶ 下载对应操作系统的版本并安装,下载地址:http://www.golangtc.com/download,譬如这里下载的是go1.6.win ...
- python抓取猫眼电影列表
抓取地址:http://maoyan.com/board/4 分析url分页规则:http://maoyan.com/board/4?offset=0 其中offset参数值为0到90 用到的库: P ...
- java.io.StreamCorruptedException: invalid stream header: EFBFBDEF 问题解决
错误方式 @Test public void testDeserializeTest() throws IOException, ClassNotFoundException { ByteArrayO ...
- 无root或sudo权限,安装mysql
这其实才是真正的linux,恰当使用权限. 网上找到的中文博客,基本上就那么几篇原创,都要编译源码.但89服务器性能太差编译一次大约半小时无法忍受,在本机上创建了standard用户去尝试几篇博客所言 ...
- DDD领域模型企业级系统Unity(五)
添加程序集: 写一个接口: public interface IPlayer { void Play(); } 两个实现类: public class NewPlay : IPlayer { publ ...
- Centos7 服务器启动jar包
首先Centos7 推荐我们这么运行项目 首先执行命令: cd /ets/systemd/system到这个目录下,新建一个 yourProjectName.service,可以把yourProjec ...
- 图学ES6-1.ECMAScript 6简介
- ThinkPHP V5.0 正式版发布
ThinkPHP5.0版本是一个颠覆和重构版本,官方团队历时十月,倾注了大量的时间和精力,采用全新的架构思想,引入了更多的PHP新特性,优化了核心,减少了依赖,实现了真正的惰性加载,支持compose ...