This is a migrated thread and some comments may be shown as answers.

Selected Items

4 Answers 194 Views
AutoCompleteView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 19 Dec 2018, 07:41 PM
Is there a way to access or set the selected item or tokens in an MVVM setup? We would love to use this a mobile combobox, but cant see to find ways to set or access the selected collection. thanks.

4 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 20 Dec 2018, 03:40 PM
Hello Andrew,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Olivier
Top achievements
Rank 1
answered on 03 Jan 2019, 11:04 AM

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.

0
Didi
Telerik team
answered on 08 Jan 2019, 10:15 AM
Hello Olivier,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Olivier
Top achievements
Rank 1
answered on 08 Jan 2019, 10:45 AM

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 !

Tags
AutoCompleteView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Didi
Telerik team
Olivier
Top achievements
Rank 1
Share this question
or