4 Answers, 1 is accepted
I am glad to hear that you want to use our new AutoCompleteView control.
The Tokens Collection of the control is read only and does not provide this functionality out of the box. In order to achieve the described scenario using MVVM setup you should create a custom behavior. I have created a sample example that shows how to implement this with Tokens. Regarding to the custom behavior implementation, please refer to the TokensBehavior.cs file from the attached project.
I hope I was helpful.
Regards,
Didi
Progress Telerik

Hello,
It's easy to get the selectedItem.
What I did was to add a Behavior EventToCommand (because I use Prism, I used their behavior).
<b:EventToCommandBehavior
Command="{Binding ItemTappedCommand, Mode=OneTime}"
EventArgsParameterPath="DataItem"
EventName="SuggestionItemSelected" />
In my Command which use a parameter (of type object), I just cast the object as a Model (the model used to populate the ItemsSource) and it works fine.
My only concern is to find how to hide the keyboard when an item is selected. I've used a KeyboardService which exposes a HideKeyboard method. It works fine on Android but it doesn't work on iOS.
Am I missing a native functionality in the AutoCompleteView ? Do you have a recommanded approach ?
public class KeyboardService : IKeyboardService
{
public async void HideKeyboard()
{
// Await 1ms to avoid a blank page.
await Task.Delay(1);
var context = MainActivity.Instance;
if (context.GetSystemService(Context.InputMethodService) is InputMethodManager inputMethodManager && context is Activity activity)
{
var token = activity.CurrentFocus?.WindowToken;
inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
activity.Window.DecorView.ClearFocus();
}
}
}
The iOS one is like this :
public class KeyboardService : IKeyboardService
{
public void HideKeyboard()
{
// Should work with only this :
UIApplication.SharedApplication.KeyWindow.EndEditing(true);
// Other things i tried :
try
{
UIApplication.SharedApplication.InputView.ResignFirstResponder();
UIApplication.SharedApplication.ResignFirstResponder();
UIApplication.SharedApplication.ReloadInputViews();
}
catch (System.Exception ex)
{
Debug.WriteLine(ex);
}
}
}
If you have any idea, I would be pleased :)
Have a good day and thanks for reading.
Thank you for the provided code.
The behavior you are observing with the keyboard is the expected one because the RadAutoCompleteView is focused. Currently, this is how the control is expected to work and there is not suitable approach that we can suggest you for changing this behavior.
Let me know if you have any additional questions or concerns.
Regards,
Didi
Progress Telerik

Hello Didi (cool name btw :) )
Thank you for your answer. I will try to find how to hide the keyboard on iOS on the Xamarin forum.
Have a good day !