I'm trying to implement IView for MVVM design pattern, which allows ViewModel to interact with the user using IView implemented class. The IView interface has functions such as Prompt, Alert & Confirm. I have three implementation of IView interface: CommandLineInteraction, WPFInteraction & TelerikInteraction. The first two are similar in behavior (i.e., they are synchronous). The third one works asynchronously.
I want TelerikInteraction to work synchronously. That means, the code following the invocation of RadWindow.Confirm() or RadWindow.Prompt() should wait until the user interacts.
Below is code snippet of all the three implementation:
//CommandLine Implementation
public CustomConfirmResult Confirm(string message) {
Console.WriteLine(message);
Console.WriteLine("[Y]es [N]o");
string s = Console.ReadLine();
if(s == y || s == Y)
return CustomConfirmResult.Yes;
else
return CustomConfirmResult.No;
}
//Windows Implementation
public CustomConfirmResult Confirm(string message) {
MessageBoxResult mbr = MessageBox.Show(message, "", MessageBoxButton.OKCancel);
if(mbr == MessageBoxResult.OK)
return CustomConfirmResult.Yes;
else
return CustomConfirmResult.No;
}
//Telerik Implementation
public CustomConfirmResult Confirm(string message) {
CustomConfirmResult result;
RadWindow.Confirm(new DialogParameters{
Content=message,
Closed = (o1, e1) =>{
if(e1.DialogResult == true)
result = CustomConfirmResult.Yes;
else
result = CustomConfirmResult.No;
}
});
return result; //Executed before user interacts with the confirm dialog
}
How do I make these implementations similar in behavior?
Thanks,
Sunil Kumar