2010-11-30 117 views
16

我目前在C#中使用WPF开发应用程序,我一直只使用WF。通常情况下,如果我要问用户的一个问题,而不是让我自己对话,我用WPF应用程序中的DialogResult C#

DialogResult result = MessageBox.show("My Message Question", "My Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 

这是我使用了一个WPF形式的DialogResult似乎没有可用的第一次。我用什么来获得相同的效果。

感谢您的帮助。

回答

32

这里是你怎么做相同的WPF:

MessageBoxResult result = MessageBox.Show("My Message Question", "My Title", MessageBoxButton.YesNo, MessageBoxImage.Question); 
if (result == MessageBoxResult.Yes) 
{ 
    // Do this 
}
7

改为使用MessageBoxResult。并使用这个MessageBox类。但是这个消息框看起来会非常难看的“经典”风格。

另一种选择是使用Extended WPF toolkit

另一个选择是去here和下载CrossTechnologySamples.exe然后寻找到VistaBridge项目。我建议你在这里好好看看,因为你会发现其他对话框的样本(如FileOpen,FileSave等),这些样本在WPF中默认不存在。

+1

的的Microsoft.Win32的OpenFileDialog和SaveFileDialog在WPF工作得很好......并且是.NET FW的一部分。 – 2010-11-30 21:22:01