2011-07-29 2 views
1

MView 디자인 패턴 용 IView를 구현하려고합니다.이 패턴을 사용하면 ViewModel이 IView 구현 클래스를 사용하여 사용자와 상호 작용할 수 있습니다. IView 인터페이스는 Prompt, Alert & Confirm과 같은 기능을 가지고 있습니다. 내가 IView 인터페이스의 세 가지 구현을 가지고 : CommandLineInteraction, WPFInteraction & TelerikInteraction. 처음 두 개는 행동이 유사합니다 (즉, 동기식입니다). 세 번째는 비동기 적으로 작동합니다.UI 스레드의 비동기식 동기식 호출로 변환

TelerikInteraction이 동 기적으로 작동하기를 원합니다. 즉, RadWindow.Confirm() 또는 RadWindow.Prompt() 호출 후의 코드는 사용자가 상호 작용할 때까지 대기해야합니다.

//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 
    } 

가 어떻게 행동이 구현 비슷한해야합니까 : 아래

는 모두 세 가지 구현의 코드인가?

감사합니다,

선일 쿠마르

답변

1

는 실버 라이트는 비동기 적으로 작동하도록 설계되었습니다. 동기식으로 작동 시키려고하면 제품의 응답 성이 제한됩니다.

대신 MessageBox 사용을 중지하고 완전히 비동기 코딩 모델로 이동해야합니다. 으로 onCancel 및 onConfirm 대표 또는 행동 (또는 onYes, onNo 또는 무엇이든 당신이 선호)를 취

갖는 도우미 메서드는 질문 & 대답이 후하다 상황의 종류를 코딩 할 수있는 가장 쉬운 방법입니다.

+0

감사합니다. 이런 식으로 할 것입니다. – sunilkumarba