I need to have yes No Cancel confirmation window in my silverlight app.
I am trying to use child window for this purp开发者_如何学Pythonose.
But this.Show();
doesn't wait till the user gives his input.
Any help ?
Thanks
PS: i m new to silverlight
If you'd be fine just with OK and Cancel buttons you could also use the Messagebox although it doesn't look so fancy.
MessageBoxResult result = MessageBox.Show("Lorem ipsum doso mitus dasam ...",
"The title", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK) {
MessageBox.Show("You clicked OK");
}
Use a child form as you are currently just rearrange the code where Show
is called:-
void SomeMethod()
{
var dialog = new YesNoCancelDialog();
dialog.Closed += (s, args) =>
{
switch (dialog.Result)
{
//Handle resulting user choice
}
}
dialog.Show();
}
Check out this project http://silverlightmsgbox.codeplex.com/. It presents a simple but presentable implementation of several useful message boxes i.e. confirm, error, info, user input, etc. and might be helpful to you. Good luck.
If you want to wait for user input until the application continues, you need to think about implementing a modal dialog, you can search google for many many implementations on this, bit if you would like more help, I can give you some pointers :)
From the Silverlights forums: http://forums.silverlight.net/forums/p/86341/200660.aspx
If you are using System.Windows.MessageBox, then make sure you are calling .Show() on the UI thread. Also, evaluate the arguments to MessageBox.Show prior to passing the closure to BeginInvoke, to avoid unsafe thread accesses.
var message = MyUnsafeObjectAccess.Foobar;
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(message)); // safe
精彩评论