void IAtomListItem.OnDisappearing(AtomListView owner)
 {
     foreach (View child in Children)
     {
         if (child.BindingContext != null)
         {
             (child as IAtomListItem)?.OnDisappearing(owner);
         }
     }
 }
示例#2
0
        private void Init()
        {
            cancelButton.Command = new AtomCommand(async() => {
                await DependencyService.Get <INavigation>().PopAsync();
            });

            if (Chooser.AllowMultipleSelection)
            {
                // take navigator list...
                listView = new AtomNavigatorListView();

                this.ToolbarItems.Add(new ToolbarItem {
                    Text    = "Done",
                    Command = DoneCommand
                });


                okButton.Command = DoneCommand;
            }
            else
            {
                listView            = new AtomListView();
                listView.TapCommand = DoneCommand;


                okButton.IsVisible = false;
                Grid.SetColumnSpan(cancelButton, 2);
            }

            listView.ItemsChanged += ListView_ItemsChanged;

            Grid.SetColumnSpan(listView, 2);

            this.Title = Chooser.PromptText;

            listView.ItemTemplate        = Chooser.ItemTemplate;
            listView.GroupDisplayBinding = Chooser.GroupDisplayBinding;
            listView.GroupHeaderTemplate = Chooser.GroupHeaderTemplate;
            listView.IsGroupingEnabled   = Chooser.IsGroupingEnabled;



            //listView.ItemsSource = Chooser.ItemsSource;

            listView.SetBinding(AtomListView.ItemsSourceProperty, new Binding()
            {
                Source = Chooser,
                Path   = nameof(AtomChooser.ItemsSource)
            });

            Grid.SetRow(listView, 2);

            searchBar.IsVisible = Chooser.ShowSearch;

            addButton.IsVisible = Chooser.AddNewCommand != null;
            addButton.Command   = Chooser.AddNewCommand;
            addButton.Text      = Chooser.AddNewLabel;

            if (searchBar.IsVisible)
            {
                UIAtomsApplication.Instance.SetTimeout(() => {
                    searchBar.Focus();
                }, TimeSpan.FromMilliseconds(100));

                searchBar.TextChanged += (s, e) => {
                    string st = e.NewTextValue;

                    Chooser.SearchText = st;

                    string fp = Chooser.FilterPath;
                    if (string.IsNullOrWhiteSpace(fp))
                    {
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(st))
                    {
                        listView.SetBinding(AtomListView.ItemsSourceProperty, new Binding()
                        {
                            Source = Chooser,
                            Path   = nameof(AtomChooser.ItemsSource)
                        });
                    }
                    else
                    {
                        var list = Chooser.ItemsSource.Cast <object>();

                        var glist = list as IEnumerable <IGrouping <object, object> >;
                        if (glist != null)
                        {
                            // grouped list filtering...

                            listView.ItemsSource = glist.Where(x => x.Any(i => Filter(i, st, fp)));
                        }
                        else
                        {
                            listView.ItemsSource = list.Where(i => Filter(i, st, fp));
                        }
                    }
                };
            }

            theGrid.Children.Add(listView);
        }