Chozarajan p

Chozarajan p

  • NA
  • 9
  • 591

The Context was not cast into Activity for latest Xamarin

Jul 6 2018 2:11 AM
Hi All,
 
I have created a new simple Dot Net project with a separate UI and ViewModel project for Android. I have used a simple Xamarin.Android EditText control to rendered in Forms control. In some scenarios, I will handle the keyboard manually. So I have used the below codes to handle the keyboard. But the Context was not cast to Activity. The specified case was not found exception has occurred.
  1. Window window = ((Activity)this.Context).Window;  
  2.         InputMethodManager mgr = (InputMethodManager)((Activity)this.Context).GetSystemService(Context.InputMethodService);  
  3.   
  4.         if (window != null)  
  5.         {  
  6.             window.SetSoftInputMode(SoftInput.StateHidden);  
  7.             mgr.HideSoftInputFromWindow(this.WindowToken, 0);  
  8.         }  
I have attached the simple project to this post. Please help me to use the keypad manually.
 
Thanks in advance.

Attachment: SampleWithSource.zip