如何在C#/WPF (.NET 3.5)中将自定义UserControl
显示为对话框?
发布于 2009-08-11 18:25:11
将其放在Window中并调用Window.ShowDialog。(另外,如果尚未添加对PresentationCore、WindowsBase和PresentationFramework的引用,请添加这些引用。)
private void Button1_Click(object sender, EventArgs e)
{
Window window = new Window
{
Title = "My User Control Dialog",
Content = new MyUserControl()
};
window.ShowDialog();
}
发布于 2013-08-30 16:08:14
Window window = new Window
{
Title = "My User Control Dialog",
Content = new OpenDialog(),
SizeToContent = SizeToContent.WidthAndHeight,
ResizeMode = ResizeMode.NoResize
};
window.ShowDialog();
对我来说就像变魔术一样。它可以作为一个模式对话框吗?
答案: ShowDialog it self make it as Modal Dialog....。
发布于 2015-04-06 14:17:58
namespace System.Window.Form
{
public static class Ext
{
public static DialogResult ShowDialog(this UserControl @this, string title)
{
Window wind = new Window() { Title = title, Content = @this };
return wind.ShowDialog();
}
}
}
它的用法可能和UserControlInstance.ShowDialog()一样简单。更好的自定义实现方法是扩展Window类,并使用设计器和代码对其进行自定义,以获得任何功能。
https://stackoverflow.com/questions/1262115
复制相似问题