C# 如何在 Silverlight 中创建弹出对话框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/260062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:18:36  来源:igfitidea点击:

How do I create a Popup Dialog box in Silverlight?

c#.netsilverlightsilverlight-2.0

提问by midas06

I'd like to create a popup dialog box in silverlight in which i can manipulate controls, enter data, and return a value. I want it to be modal, so that when it is open, the page "Below" is inaccessible. I havent found an easy way to do this yet. Any suggestions?

我想在 Silverlight 中创建一个弹出对话框,我可以在其中操作控件、输入数据和返回值。我希望它是模态的,这样当它打开时,“下面”页面就无法访问了。我还没有找到一种简单的方法来做到这一点。有什么建议?

采纳答案by Shawn Oster

I know the question asked for a Silverlight 2 solution but in Silverlight 3 (Beta now, RTW in July 2009) there is a built-in ChildWindow that can do everything you're looking for.

我知道要求 Silverlight 2 解决方案的问题,但在 Silverlight 3(现在是 Beta,2009 年 7 月为 RTW)中有一个内置的 ChildWindow 可以完成您正在寻找的一切。

回答by Gulzar Nazim

I haven't found a perfect solution either. The closest I have seen is this: Using Popup to create a Dialog class

我也没有找到完美的解决方案。我见过的最接近的是: Using Popup to create a Dialog class

If it is ok to be non-modal, you can try this tip using HtmlPage.PopupWindow(). How to Popup a Browser Window

如果可以使用非模态,您可以使用 HtmlPage.PopupWindow() 尝试此提示。 如何弹出浏览器窗口

回答by Kevin

I'm new to the Sliverlight framework and am just starting to figure it out, but I have a similar need for a popup modal dialog box. I just tried an idea that looks promising:

我是 Sliverlight 框架的新手,刚刚开始弄明白,但我对弹出式模式对话框有类似的需求。我刚刚尝试了一个看起来很有希望的想法:

  1. I created a Rectangle (named "Shield") that covers my entire application area. It exists on top of everything in the main app. I set the fill-brush to White, and the opacity-brush to 81% so that the main app contents show through, but lightly (as in disabled). Then make sure the "Shield" is hit-testable. Now, when the "Shield" is visible, it will also, in effect, block all input to the controls below (at least from the mouse, haven't tried keyboard yet). When the app initializes, set the "Shield" visibility to Collapsed. In that state it won't block input to the main app.
  2. The dialog box is then constructed on another canvas element that exists in the z-order on top of the shield. Normally the dialog box will be invisible, but when I need it, I just set the "Shield" to visible, and the dialog to visible. Since the dialog is on top of the "Shield" I get a very modal-like behavior. When the dialog box is closed, make both the dialog canvas and "Shield" canvas invisible again and the main app is again active.
  1. 我创建了一个矩形(名为“Shield”),它覆盖了我的整个应用程序区域。它存在于主应用程序的所有内容之上。我将填充画笔设置为白色,将不透明度画笔设置为 81%,以便主要应用程序内容显示出来,但很轻(如禁用)。然后确保“Shield”是可命中测试的。现在,当“Shield”可见时,它实际上也将阻止所有输入到下面的控件(至少来自鼠标,还没有尝试过键盘)。当应用程序初始化时,将“Shield”可见性设置为 Collapsed。在这种状态下,它不会阻止对主应用程序的输入。
  2. 然后在盾牌顶部以 z 顺序存在的另一个画布元素上构建对话框。通常对话框是不可见的,但是当我需要它时,我只需将“Shield”设置为可见,并将对话框设置为可见。由于对话框位于“Shield”之上,因此我得到了一种非常类似于模态的行为。当对话框关闭时,再次使对话框画布和“Shield”画布不可见,主应用程序再次处于活动状态。

I'm sure this the most brute-force way of doing it and that I will eventually zero in on a more elegant construct, but it works for now.

我确信这是最暴力的方法,我最终会在一个更优雅的构造上归零,但它现在有效。

回答by Senthil

I had the same requirement and ScottGu's Building a Basic Modal Dialog Using a User Controlwas the best solution that fit my requirement.

我有同样的要求,ScottGu 的使用用户控件构建基本模态对话框是符合我要求的最佳解决方案。

回答by Bryan Legend

Here's a free library that provides one: http://www.vectorlight.net/demos/popup_dialogs.aspx

这是一个提供一个免费库:http: //www.vectorlight.net/demos/popup_dialogs.aspx