2010-11-30 113 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