嗯,我使用一個窗口作爲我的自定義消息框與幾個控件顯示/填充文本取決於哪個構造函數被調用。自定義消息框建議
我有一個定義的事件,它是通過原始類訂閱的,一旦按鈕被點擊就會觸發。
但是我不明白如何有效地使用它,最好是我想返回一個bool,無論是單擊還是否,但顯然我的代碼將繼續執行,因此,該方法是子按鈕到按鈕單擊。以下是一些使問題更清楚的示例代碼。
消息框窗口
public partial class CustomMessageBox : Window
{
public delegate void MessageBoxHandler(object sender, EventArgs e);
public event MessageBoxHandler MessageBoxEvent;
public CustomMessageBox()
{
InitializeComponent();
}
public CustomMessageBox(string message)
{
InitializeComponent();
this.txtdescription.Text = message;
}
public CustomMessageBox(string message, string title, string firstBtnText)
{
InitializeComponent();
this.lbltitle.Content = title;
this.txtdescription.Text = message;
this.btnstart.Content = firstBtnText;
}
}
public static class MessageBoxButtonClick
{
public static bool Yes { get; set; }
public static bool No { get; set; }
public static bool Cancel { get; set; }
}
窗口,實例化的MessageBox窗口
private void StartProcess_Click(object sender, System.Windows.RoutedEventArgs e)
{
foreach (var result in results)
{
if(result.ToBeProcessed)
_validResults.Add(new ToBeProcessed(result.Uri, result.Links));
}
_msgbox = new CustomMessageBox("Each Uri's backlinks will now be collected from Yahoo and filtered, finally each link will be visited and parsed. The operation is undertaken in this manner to avoid temporary IP Blocks from Yahoo's servers.", "Just a FYI", "OK");
_msgbox.MessageBoxEvent += (MessageBoxHandler);
if (_msgBoxProceed)
{
_msgbox.Close();
Yahoo yahoo = new Yahoo();
yahoo.Status.Sending += (StatusChange);
//What I'd like to happen here is the code simply stop, like it does when calling a messagebox is winforms
//e.g.
// if(ProceedClicked == true)
// do stuff
// yahoo.ScrapeYahoo(_validResults[Cycle].Uri, _validResults[Cycle].LinkNumber);
//Cycle++;
}
else
{
_msgbox.Close();
}
}
private void MessageBoxHandler(object sender, EventArgs e)
{
if (MessageBoxButtonClick.Yes)
{
ProceedClicked = true;
}
else
{
ProceedClicked = false;
}
}
希望這使得它很清楚,我不能把任何執行代碼即調用一定方法,因爲在我的應用程序中多次使用它。
嘿馬克,我沒有意識到Windows中的WPF有ShowDialog屬性,所以我的問題得到解決。 謝謝隊友。 – Ash 2010-08-04 11:52:54