Selected Items

5 posts, 0 answers
  1. Andrew
    Andrew avatar
    7 posts
    Member since:
    Dec 2012

    Posted 19 Dec 2018 Link to this post

    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.
  2. Didi
    Admin
    Didi avatar
    250 posts

    Posted 20 Dec 2018 Link to this post

    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
  3. Olivier
    Olivier avatar
    15 posts
    Member since:
    Aug 2017

    Posted 03 Jan in reply to Didi Link to this post

    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.

  4. Didi
    Admin
    Didi avatar
    250 posts

    Posted 08 Jan Link to this post

    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
  5. Olivier
    Olivier avatar
    15 posts
    Member since:
    Aug 2017

    Posted 08 Jan in reply to Didi Link to this post

    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 !

Back to Top