Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Can the Picker list be filtered when it gains focus?

$
0
0

I have a textbox that is used to filter a picker list. I need the picker list to be filtered either when the picker gains focus, OR when the textbox loses focus. I have tried both ways, and neither work. It's as if the MessagingCenter is alerting my VM after the fact. It seems like this should be pretty easy, but I cannot come up with a solution.

How can I filter/update that list BEFORE the picker list is shown?

FWIW, here is the pertinent code"

<br />    namespace DatabaseTest.ViewModels
    {
        public class MyViewModel : INotifyPropertyChanged
        {
            public MyViewModel()
            {
                List mystuff = new List();
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
                {
                    conn.CreateTable();
                    mystuff = conn.Table().ToList();
                }
                myList = new ObservableCollection(mystuff);
                MessagingCenter.Subscribe<FocusedTriggerAction> (this, "changeList", (sender) => 
                {
                    if (mylookupstring == "")
                        testme = 1;
                    else
                        myList = new ObservableCollection<MyOptions>(mystuff.Where(o => o.SpecFullName.Contains(mylookupstring)));
                });
            }
            string mylookupstring = string.Empty;
            int testme = 0;
            public event PropertyChangedEventHandler PropertyChanged;
            void OnPropertyChanged([CallerMemberName] string name = "")
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
            }
            public string myLookupString
            {
                get { return mylookupstring; }
                set
                {
                    mylookupstring = value;
                    mylookupstring = mylookupstring.ToUpper();
                    OnPropertyChanged();
                }
            }
            private ObservableCollection<MyOptions> _mylist;
            public ObservableCollection<MyOptions> myList
            {
                get { return _mylist; }
                set
                {
                    if (_mylist != value)
                    {
                        _mylist = value;
                        OnPropertyChanged();
                    }
                }
            }
        }
    }


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>