public OpportunitiesPage() { ViewModel.OkButtonTapped += HandleWelcomeViewDisappearing; var collectionView = new CollectionView { ItemTemplate = new OpportunitiesDataTemplate(), SelectionMode = SelectionMode.Single, }; collectionView.SelectionChanged += HandleSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(OpportunitiesViewModel.VisibleOpportunitiesCollection)); _refreshView = new RefreshView { Content = collectionView }; _refreshView.SetBinding(RefreshView.CommandProperty, nameof(OpportunitiesViewModel.RefreshDataCommand)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(OpportunitiesViewModel.IsCollectionRefreshing)); var addButtonToolBar = new ToolbarItem { IconImageSource = "Add", AutomationId = AutomationIdConstants.AddOpportunityButton }; addButtonToolBar.Clicked += HandleAddButtonClicked; ToolbarItems.Add(addButtonToolBar); var searchBar = new SearchBar { AutomationId = AutomationIdConstants.OpportunitySearchBar }; searchBar.SetBinding(SearchBar.TextProperty, nameof(OpportunitiesViewModel.SearchBarText)); _mainLayout = new RelativeLayout(); _mainLayout.Children.Add(searchBar, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width)); _mainLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.RelativeToParent(getSearchBarHeight), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height - getSearchBarHeight(parent))); Title = PageTitleConstants.OpportunitiesPage; NavigationPage.SetBackButtonTitle(this, ""); Content = _mainLayout; double getSearchBarHeight(RelativeLayout p) => searchBar.Measure(p.Width, p.Height).Request.Height; }
public OpportunitiesPage() { #region Create the ListView _listView = new ListView { ItemTemplate = new DataTemplate(typeof(OpportunitiesViewCell)), RowHeight = 75 }; _listView.IsPullToRefreshEnabled = true; _listView.SetBinding(ListView.ItemsSourceProperty, nameof(ViewModel.ViewableOpportunitiesData)); _listView.SetBinding(ListView.RefreshCommandProperty, nameof(ViewModel.RefreshAllDataCommand)); #endregion #region Initialize the Toolbar Add Button _addButtonToolBar = new ToolbarItem { Icon = "Add", AutomationId = AutomationIdConstants.AddOpportunityButton }; ToolbarItems.Add(_addButtonToolBar); #endregion #region Create Searchbar _searchBar = new SearchBar { AutomationId = AutomationIdConstants.OpportunitySearchBar }; _searchBar.SetBinding(SearchBar.TextProperty, nameof(ViewModel.SearchBarText)); #endregion _mainLayout = new RelativeLayout(); Func <RelativeLayout, double> getSearchBarHeight = (p) => _searchBar.Measure(p.Width, p.Height).Request.Height; _mainLayout.Children.Add(_searchBar, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width) ); _mainLayout.Children.Add(_listView, Constraint.Constant(0), Constraint.RelativeToParent(parent => getSearchBarHeight(parent)), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height - getSearchBarHeight(parent)) ); Title = PageTitleConstants.OpportunitiesPageTitle; NavigationPage.SetBackButtonTitle(this, ""); Content = _mainLayout; DisplayWelcomeView(); }