public static RefreshView BindSyncCollection(this RefreshView refreshView, string nameOfSyncCollection) { refreshView.SetBinding(RefreshView.CommandProperty, new Binding(nameof(IReloadableViewModel.ReloadCommand))); refreshView.SetBinding(RefreshView.IsRefreshingProperty, new Binding(nameOfSyncCollection + ".SyncStatusHandler.State", BindingMode.OneWay, new SyncCollectionIsRunningConverter())); return(refreshView); }
ContentPage CollectionViewPage() { BindingContext = new _11311ViewModel(); var collectionView = new CollectionView { Footer = new BoxView { BackgroundColor = Color.Red, HeightRequest = 53 } }; collectionView.SetBinding(ItemsView.ItemsSourceProperty, nameof(_11311ViewModel.ScoreCollectionList)); var refreshView = new RefreshView { Content = collectionView }; refreshView.SetBinding(RefreshView.CommandProperty, nameof(_11311ViewModel.PopulateCollectionCommand)); refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(_11311ViewModel.IsRefreshing)); var page = new ContentPage { Title = "CollectionView Page", Content = refreshView }; return(page); }
public PhotoListPage() { ViewModel.RefreshFailed += HandleRefreshFailed; var addPhotosButton = new ToolbarItem { Text = "+", AutomationId = AutomationIdConstants.AddPhotoButton }; addPhotosButton.Clicked += HandleAddContactButtonClicked; ToolbarItems.Add(addPhotosButton); var photoCollectionView = new CollectionView { ItemTemplate = new PhotoDataTemplate(), SelectionMode = SelectionMode.Single, AutomationId = AutomationIdConstants.PhotosCollectionView, }; photoCollectionView.SelectionChanged += HandlePhotoCollectionSelectionChanged; photoCollectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(PhotoListViewModel.AllPhotosList)); _photosCollectionRefreshView = new RefreshView { Content = photoCollectionView }; _photosCollectionRefreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(PhotoListViewModel.IsRefreshing)); _photosCollectionRefreshView.SetBinding(RefreshView.CommandProperty, nameof(PhotoListViewModel.RefreshCommand)); Title = PageTitles.PhotoListPage; Content = _photosCollectionRefreshView; }
public DogImageListPage() { ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; var collectionView = new CollectionView { ItemTemplate = new DogImageListDataTemplateSelector(), SelectionMode = SelectionMode.Single, EmptyView = new Label { Text = "🐶", FontSize = 128, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, } }; collectionView.SelectionChanged += HandleCollectionViewCollectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(DogImageListViewModel.DogImageCollection)); _refreshView = new RefreshView { Content = collectionView, RefreshColor = Color.FromHex("1F2B2E") }; _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(DogImageListViewModel.IsDogImageCollectionRefreshing)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(DogImageListViewModel.RefreshDogCollectionCommand)); Title = "Favorite Dogs"; Content = _refreshView; }
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 RepositoryPage(RepositoryViewModel repositoryViewModel, AnalyticsService analyticsService, SortingService sortingService) : base(PageTitles.RepositoryPage, repositoryViewModel, analyticsService) { ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; SearchBarTextChanged += HandleSearchBarTextChanged; var collectionView = new CollectionView { ItemTemplate = new RepositoryDataTemplateSelector(sortingService), BackgroundColor = Color.Transparent, SelectionMode = SelectionMode.Single, AutomationId = RepositoryPageAutomationIds.CollectionView }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(RepositoryViewModel.VisibleRepositoryList)); var repositoriesListRefreshView = new RefreshView { AutomationId = RepositoryPageAutomationIds.RefreshView, Content = collectionView }; repositoriesListRefreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.RefreshControlColor)); repositoriesListRefreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(RepositoryViewModel.IsRefreshing)); repositoriesListRefreshView.SetBinding(RefreshView.CommandProperty, nameof(RepositoryViewModel.PullToRefreshCommand)); var settingsToolbarItem = new ToolbarItem { Text = "Settings", Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default, AutomationId = RepositoryPageAutomationIds.SettingsButton, }; settingsToolbarItem.Clicked += HandleSettingsToolbarItemCliked; ToolbarItems.Add(settingsToolbarItem); var sortToolbarItem = new ToolbarItem { Text = "Sort", IconImageSource = Device.RuntimePlatform is Device.iOS ? "Sort" : null, Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default, AutomationId = RepositoryPageAutomationIds.SortButton, }; sortToolbarItem.Clicked += HandleSortToolbarItemCliked; ToolbarItems.Add(sortToolbarItem); Content = repositoriesListRefreshView; }
void Construct() { BindingContext = new RefreshViewModel(); var refreshView = new RefreshView { BackgroundColor = Color.Red, RefreshColor = Color.Yellow }; refreshView.SetBinding(RefreshView.CommandProperty, "RefreshCommand"); refreshView.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing"); refreshView.On <WindowsOS>().SetRefreshPullDirection(RefreshPullDirection.BottomToTop); var listView = new ListView { ItemTemplate = new DataTemplate(() => { var stackLayout = new StackLayout { Orientation = StackOrientation.Horizontal }; var boxView = new BoxView { WidthRequest = 40 }; var infoLabel = new Label(); boxView.SetBinding(BoxView.ColorProperty, "Color"); infoLabel.SetBinding(Label.TextProperty, "Name"); stackLayout.Children.Add(boxView); stackLayout.Children.Add(infoLabel); return(new ViewCell { View = stackLayout }); }) }; listView.SetBinding(ListView.ItemsSourceProperty, "Items"); refreshView.Content = listView; Content = refreshView; }
public OpportunitiesPage() { SearchBarTextChanged += HandleSearchBarTextChanged; ViewModel.OkButtonTapped += HandleWelcomeViewDisappearing; var collectionView = new CollectionView { ItemTemplate = new OpportunitiesDataTemplate(), SelectionMode = SelectionMode.Single, }; collectionView.SelectionChanged += HandleSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(OpportunitiesViewModel.VisibleOpportunitiesCollection)); var 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", Text = "Add", AutomationId = AutomationIdConstants.AddOpportunityButton, Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default }; addButtonToolBar.Clicked += HandleAddButtonClicked; ToolbarItems.Add(addButtonToolBar); _mainLayout = new RelativeLayout(); _mainLayout.Children.Add(refreshView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); Title = PageTitleConstants.OpportunitiesPage; NavigationPage.SetBackButtonTitle(this, ""); Content = _mainLayout; }
public CollectionViewPage(string title, BaseListViewModel viewModel) : base(title, viewModel) { var collectionView = new CollectionView { ItemTemplate = new ListDataTemplate() }; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ObservableCollectionViewModel.DataList)); var refreshView = new RefreshView { Content = collectionView }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ObservableCollectionViewModel.IsRefreshing)); refreshView.SetBinding(RefreshView.CommandProperty, nameof(ObservableCollectionViewModel.PullToRefreshCommand)); Content = refreshView; }
public RepositoryPage(RepositoryViewModel repositoryViewModel, GitHubAuthenticationService gitHubAuthenticationService, bool isInitiatedByCallBackUri = false) : base(PageTitles.RepositoryPage, repositoryViewModel) { _shouldNavigateToSettingsPageOnAppearing = isInitiatedByCallBackUri; _gitHubAuthenticationService = gitHubAuthenticationService; ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; SearchBarTextChanged += HandleSearchBarTextChanged; var collectionView = new CollectionView { ItemTemplate = new RepositoryDataTemplate(), BackgroundColor = Color.Transparent, SelectionMode = SelectionMode.Single }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(RepositoryViewModel.VisibleRepositoryList)); var repositoriesListRefreshView = new RefreshView { Content = collectionView }; repositoriesListRefreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.RefreshControlColor)); repositoriesListRefreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(RepositoryViewModel.IsRefreshing)); repositoriesListRefreshView.SetBinding(RefreshView.CommandProperty, nameof(RepositoryViewModel.PullToRefreshCommand)); var settingsToolbarItem = new ToolbarItem { Text = "Settings", Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default }; settingsToolbarItem.Clicked += HandleSettingsToolbarItem; ToolbarItems.Add(settingsToolbarItem); Content = repositoriesListRefreshView; }
public PowerBIReportsListPage() { var collectionView = new CollectionView { SelectionMode = SelectionMode.Single, ItemTemplate = new GroupListDataTemplate() }; collectionView.SelectionChanged += HandleSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(PowerBIReportsListViewModel.VisibleReportsListData)); var refreshView = new RefreshView { Content = collectionView }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(PowerBIReportsListViewModel.IsReportsListRefreshing)); refreshView.SetBinding(RefreshView.CommandProperty, nameof(PowerBIReportsListViewModel.RefreshReportsListCommand)); Title = "Reports List"; Content = refreshView; }
public Issue8392() { Title = "Issue 8392"; var collectionView = new CollectionView { ItemTemplate = new Issue8392DataTemplate() }; collectionView.SetBinding(ItemsView.ItemsSourceProperty, nameof(Issue8392ViewModel.DataList)); var refreshView = new RefreshView { Content = collectionView }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(Issue8392ViewModel.IsRefreshing)); refreshView.SetBinding(RefreshView.CommandProperty, nameof(Issue8392ViewModel.PullToRefreshCommand)); Content = refreshView; BindingContext = new Issue8392ViewModel(); }
public TextResultsListPage() { ViewModel.ErrorTriggered += HandleErrorTriggered; ViewModel.PhilipsHueBridgeConnectionFailed += HandlePhilipsHueBridgeConnectionFailed; BaseSignalRService.InitializationFailed += HandleInitializationFailed; var setupPageToolbarItem = new ToolbarItem { Text = "Setup" }; setupPageToolbarItem.Clicked += HandleSetupPageToolbarItemClicked; ToolbarItems.Add(setupPageToolbarItem); var textModelList = new CollectionView { ItemTemplate = new TextMoodDataTemplateSelector(), BackgroundColor = Color.Transparent }; textModelList.SetBinding(CollectionView.ItemsSourceProperty, nameof(TextResultsListViewModel.TextList)); var refreshView = new RefreshView { RefreshColor = Device.RuntimePlatform is Device.iOS ? ColorConstants.BarTextColor : ColorConstants.BarBackgroundColor, Content = textModelList }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(TextResultsListViewModel.IsRefreshing)); refreshView.SetBinding(RefreshView.CommandProperty, nameof(TextResultsListViewModel.PullToRefreshCommand)); Title = PageTitles.TextResultsPage; this.SetBinding(BackgroundColorProperty, nameof(TextResultsListViewModel.BackgroundColor)); Content = refreshView; }
public PersonListPage() { ViewModel.ErrorTriggered += HandleErrorTriggered; var addButtonToolBarItem = new ToolbarItem { IconImageSource = "Add", AutomationId = AutomationIdConstants.PersonListPage_AddButton }; addButtonToolBarItem.Clicked += HandleAddButtonClicked; ToolbarItems.Add(addButtonToolBarItem); var personList = new CollectionView { ItemTemplate = new PersonListDataTemplate(), BackgroundColor = ColorConstants.PageBackgroundColor, AutomationId = AutomationIdConstants.PersonListPage_PersonList }; personList.SelectionChanged += HandleSelectionChanged; personList.SetBinding(CollectionView.ItemsSourceProperty, nameof(PersonListViewModel.PersonList)); var refreshView = new RefreshView { RefreshColor = Color.Black, Content = personList }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(PersonListViewModel.IsRefreshing)); refreshView.SetBinding(RefreshView.CommandProperty, nameof(PersonListViewModel.PullToRefreshCommand)); var activityIndicator = new ActivityIndicator { AutomationId = AutomationIdConstants.PersonListPage_ActivityIndicator }; activityIndicator.SetBinding(IsVisibleProperty, nameof(PersonListViewModel.IsDeletingPerson)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(PersonListViewModel.IsDeletingPerson)); var whiteOverlayBoxView = new BoxView { BackgroundColor = new Color(1, 1, 1, 0.75) }; whiteOverlayBoxView.SetBinding(IsVisibleProperty, nameof(PersonListViewModel.IsDeletingPerson)); var relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(refreshView, Constraint.Constant(0), Constraint.Constant(0)); relativeLayout.Children.Add(whiteOverlayBoxView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); relativeLayout.Children.Add(activityIndicator, Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityWidth(parent, activityIndicator) / 2), Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityHeight(parent, activityIndicator) / 2)); Content = relativeLayout; Title = PageTitles.PersonListPage;
public ReferringSitesPage(DeepLinkingService deepLinkingService, ReferringSitesViewModel referringSitesViewModel, Repository repository, IAnalyticsService analyticsService, ThemeService themeService, ReviewService reviewService, IMainThread mainThread) : base(referringSitesViewModel, analyticsService, mainThread, PageTitles.ReferringSitesPage) { _reviewService = reviewService; _deepLinkingService = deepLinkingService; ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; reviewService.ReviewCompleted += HandleReviewCompleted; var collectionView = new CollectionView { AutomationId = ReferringSitesPageAutomationIds.CollectionView, BackgroundColor = Color.Transparent, ItemTemplate = new ReferringSitesDataTemplate(), SelectionMode = SelectionMode.Single, ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical), //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 Header = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = ReferringSitesDataTemplate.BottomPadding } : null, Footer = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = ReferringSitesDataTemplate.TopPadding } : null, EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView) .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled)) .Bind(EmptyDataView.TitleProperty, nameof(ReferringSitesViewModel.EmptyDataViewTitle)) .Bind(EmptyDataView.DescriptionProperty, nameof(ReferringSitesViewModel.EmptyDataViewDescription)) }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList)); _refreshView = new RefreshView { AutomationId = ReferringSitesPageAutomationIds.RefreshView, CommandParameter = (repository.OwnerLogin, repository.Name, repository.Url, _refreshViewCancelltionTokenSource.Token), Content = collectionView }; _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing)); var relativeLayout = new RelativeLayout(); //Add Title and Close Button to UIModalPresentationStyle.FormSheet if (Device.RuntimePlatform is Device.iOS) { const int titleTopMargin = 10; const int titleRowHeight = 50; var closeButton = new Button { Text = ReferringSitesPageConstants.CloseButtonText, FontFamily = FontFamilyConstants.RobotoRegular, HeightRequest = titleRowHeight * 3 / 5, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, AutomationId = ReferringSitesPageAutomationIds.CloseButton, Padding = new Thickness(5, 0) }; closeButton.Clicked += HandleCloseButtonClicked; closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.CloseButtonTextColor)); closeButton.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.CloseButtonBackgroundColor)); var titleLabel = new Label { FontSize = 30, Text = PageTitles.ReferringSitesPage, FontFamily = FontFamilyConstants.RobotoMedium, }.Center().TextCenterVertical(); titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0); var titleShadow = new BoxView(); titleShadow.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.CardSurfaceColor)); if (isLightTheme(themeService.Preference)) { titleShadow.On <iOS>().SetIsShadowEnabled(true) .SetShadowColor(Color.Gray) .SetShadowOffset(new Size(0, 1)) .SetShadowOpacity(0.5) .SetShadowRadius(4); } relativeLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.Constant(titleRowHeight), //Set to `0` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height - titleRowHeight)); //Set to `parent => parent.Height` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 relativeLayout.Children.Add(titleShadow, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.Constant(titleRowHeight)); relativeLayout.Children.Add(titleLabel, Constraint.Constant(10), Constraint.Constant(0)); relativeLayout.Children.Add(closeButton, Constraint.RelativeToParent(parent => parent.Width - closeButton.GetWidth(parent) - 10), Constraint.Constant(0), Constraint.RelativeToParent(parent => closeButton.GetWidth(parent))); } else { relativeLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); } relativeLayout.Children.Add(_storeRatingRequestView, Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Height - _storeRatingRequestView.GetHeight(parent)), Constraint.RelativeToParent(parent => parent.Width)); Content = relativeLayout;
public ReferringSitesPage(ReferringSitesViewModel referringSitesViewModel, Repository repository, AnalyticsService analyticsService) : base(PageTitles.ReferringSitesPage, referringSitesViewModel, analyticsService) { const int titleRowHeight = 50; const int titleTopMargin = 15; var collectionView = new CollectionView { AutomationId = ReferringSitesPageAutomationIds.CollectionView, ItemTemplate = new ReferringSitesDataTemplateSelector(), SelectionMode = SelectionMode.Single }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.ReferringSitesCollection)); _refreshView = new RefreshView { AutomationId = ReferringSitesPageAutomationIds.RefreshView, CommandParameter = (repository.OwnerLogin, repository.Name), Content = collectionView }; _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.RefreshControlColor)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing)); //Add Title and Back Button to UIModalPresentationStyle.FormSheet if (Device.RuntimePlatform is Device.iOS) { var closeButton = new Button { AutomationId = ReferringSitesPageAutomationIds.CloseButton, Text = "Close", HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, HeightRequest = titleRowHeight * 3 / 5, Padding = new Thickness(5, 0) }; closeButton.Clicked += HandleCloseButtonClicked; closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.NavigationBarTextColor)); closeButton.SetDynamicResource(Button.BorderColorProperty, nameof(BaseTheme.TrendsChartSettingsBorderColor)); closeButton.SetDynamicResource(Button.BackgroundColorProperty, nameof(BaseTheme.NavigationBarBackgroundColor)); var titleRowBlurView = new BoxView { Opacity = 0.5 }; titleRowBlurView.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor)); collectionView.Header = new BoxView { HeightRequest = titleRowHeight + titleTopMargin }; var titleLabel = new Label { FontAttributes = FontAttributes.Bold, Text = PageTitles.ReferringSitesPage, FontSize = 30 }; titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0); var activityIndicator = new ActivityIndicator { AutomationId = ReferringSitesPageAutomationIds.ActivityIndicator, }; activityIndicator.SetDynamicResource(ActivityIndicator.ColorProperty, nameof(BaseTheme.RefreshControlColor)); activityIndicator.SetBinding(IsVisibleProperty, nameof(ReferringSitesViewModel.IsActivityIndicatorVisible)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ReferringSitesViewModel.IsActivityIndicatorVisible)); var relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); relativeLayout.Children.Add(titleRowBlurView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.Constant(titleRowHeight)); relativeLayout.Children.Add(titleLabel, Constraint.Constant(10), Constraint.Constant(0)); relativeLayout.Children.Add(closeButton, Constraint.RelativeToParent(parent => parent.Width - GetWidth(parent, closeButton) - 10), Constraint.Constant(0), Constraint.RelativeToParent(parent => GetWidth(parent, closeButton))); relativeLayout.Children.Add(activityIndicator, Constraint.RelativeToParent(parent => parent.Width / 2 - GetWidth(parent, activityIndicator) / 2), Constraint.RelativeToParent(parent => parent.Height / 2 - GetHeight(parent, activityIndicator) / 2)); Content = relativeLayout; } else { Content = _refreshView; } }
public ReferringSitesPage(DeepLinkingService deepLinkingService, ReferringSitesViewModel referringSitesViewModel, Repository repository, AnalyticsService analyticsService, ReviewService reviewService) : base(referringSitesViewModel, analyticsService, PageTitles.ReferringSitesPage) { const int titleRowHeight = 50; const int titleTopMargin = 15; _deepLinkingService = deepLinkingService; _reviewService = reviewService; ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; reviewService.ReviewCompleted += HandleReviewCompleted; var collectionView = new CollectionView { AutomationId = ReferringSitesPageAutomationIds.CollectionView, BackgroundColor = Color.Transparent, ItemTemplate = new ReferringSitesDataTemplate(), SelectionMode = SelectionMode.Single, ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical), //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 Header = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = 8 } : null, Footer = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = 8 } : null, EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView) .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled)) .Bind(EmptyDataView.TextProperty, nameof(ReferringSitesViewModel.EmptyDataViewText)) }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList)); _refreshView = new RefreshView { AutomationId = ReferringSitesPageAutomationIds.RefreshView, CommandParameter = (repository.OwnerLogin, repository.Name, repository.Url, _refreshViewCancelltionTokenSource.Token), Content = collectionView }; _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing)); var relativeLayout = new RelativeLayout(); //Add Title and Close Button to UIModalPresentationStyle.FormSheet if (Device.RuntimePlatform is Device.iOS) { const int refreshViewTopPadding = titleRowHeight + 5; var closeButton = new Button { Text = "Close", FontFamily = FontFamilyConstants.RobotoRegular, HeightRequest = titleRowHeight * 3 / 5, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, AutomationId = ReferringSitesPageAutomationIds.CloseButton, Padding = new Thickness(5, 0), }; closeButton.Clicked += HandleCloseButtonClicked; closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.NavigationBarTextColor)); closeButton.SetDynamicResource(Button.BorderColorProperty, nameof(BaseTheme.BorderButtonBorderColor)); closeButton.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.NavigationBarBackgroundColor)); var titleRowBlurView = new BoxView { Opacity = 0.5 }; titleRowBlurView.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor)); var titleLabel = new Label { FontSize = 30, Text = PageTitles.ReferringSitesPage, FontFamily = FontFamilyConstants.RobotoMedium, }; titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0); relativeLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.Constant(refreshViewTopPadding), //Set to `0` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height - refreshViewTopPadding)); //Set to `parent => parent.Height` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 relativeLayout.Children.Add(titleRowBlurView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.Constant(titleRowHeight)); relativeLayout.Children.Add(titleLabel, Constraint.Constant(10), Constraint.Constant(0)); relativeLayout.Children.Add(closeButton, Constraint.RelativeToParent(parent => parent.Width - GetWidth(parent, closeButton) - 10), Constraint.Constant(0), Constraint.RelativeToParent(parent => GetWidth(parent, closeButton))); } else { relativeLayout.Children.Add(_refreshView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); } relativeLayout.Children.Add(_storeRatingRequestView, Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Height - GetHeight(parent, _storeRatingRequestView)), Constraint.RelativeToParent(parent => parent.Width)); Content = relativeLayout; }
public RepositoryPage(RepositoryViewModel repositoryViewModel, AnalyticsService analyticsService, SortingService sortingService, DeepLinkingService deepLinkingService) : base(repositoryViewModel, analyticsService, PageTitles.RepositoryPage) { _deepLinkingService = deepLinkingService; ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed; SearchBarTextChanged += HandleSearchBarTextChanged; var collectionView = new CollectionView { ItemTemplate = new RepositoryDataTemplateSelector(sortingService), BackgroundColor = Color.Transparent, SelectionMode = SelectionMode.Single, AutomationId = RepositoryPageAutomationIds.CollectionView, //Work around for https://github.com/xamarin/Xamarin.Forms/issues/9879 Header = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = 8 } : null, Footer = Device.RuntimePlatform is Device.Android ? new BoxView { HeightRequest = 8 } : null, EmptyView = new EmptyDataView("EmptyRepositoriesList", RepositoryPageAutomationIds.EmptyDataView) .Bind <EmptyDataView, bool, bool>(IsVisibleProperty, nameof(RepositoryViewModel.IsRefreshing), convert: isRefreshing => !isRefreshing) .Bind(EmptyDataView.TextProperty, nameof(RepositoryViewModel.EmptyDataViewText)) }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(RepositoryViewModel.VisibleRepositoryList)); _refreshView = new RefreshView { AutomationId = RepositoryPageAutomationIds.RefreshView, Content = collectionView }; _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(RepositoryViewModel.IsRefreshing)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(RepositoryViewModel.PullToRefreshCommand)); var settingsToolbarItem = new ToolbarItem { Text = "Settings", IconImageSource = Device.RuntimePlatform is Device.iOS ? "Settings" : null, Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default, AutomationId = RepositoryPageAutomationIds.SettingsButton, Command = new AsyncCommand(ExecuteSetttingsToolbarItemCommand) }; ToolbarItems.Add(settingsToolbarItem); var sortToolbarItem = new ToolbarItem { Text = "Sort", Priority = 1, IconImageSource = Device.RuntimePlatform is Device.iOS ? "Sort" : null, Order = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default, AutomationId = RepositoryPageAutomationIds.SortButton, Command = new AsyncCommand(ExecuteSortToolbarItemCommand) }; ToolbarItems.Add(sortToolbarItem); //Work-around to prevent LargeNavigationBar from collapsing when CollectionView is scrolled; prevents janky animation when LargeNavigationBar collapses if (Device.RuntimePlatform is Device.iOS) { Content = new Grid { Children = { new BoxView { HeightRequest = 0 }, _refreshView } }; } else { Content = _refreshView; } }
public RefreshViewDemoPage() { RefreshViewDemoPageViewModel viewModel = new RefreshViewDemoPageViewModel(); // Define DataTemplate. DataTemplate colorItemTemplate = new DataTemplate(() => { Grid grid = new Grid { Margin = new Thickness(5), HeightRequest = 120, WidthRequest = 105 }; BoxView boxView = new BoxView(); boxView.SetBinding(BoxView.ColorProperty, "Color"); Label label = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }; label.SetBinding(Label.TextProperty, "Name"); grid.Children.Add(boxView); grid.Children.Add(label); return(grid); }); Label header = new Label { Text = "RefreshView", FontSize = 50, FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.Center }; Label pullMessage = new Label { Text = "Pull the items down to refresh the ScrollView." }; Label numberOfItems = new Label(); numberOfItems.SetBinding(Label.TextProperty, "Items.Count", stringFormat: "Number of items: {0}"); FlexLayout flexLayout = new FlexLayout { Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, AlignItems = FlexAlignItems.Center, AlignContent = FlexAlignContent.Center }; BindableLayout.SetItemsSource(flexLayout, viewModel.Items); BindableLayout.SetItemTemplate(flexLayout, colorItemTemplate); // Set the FlexLayout as the child of the ScrollView. ScrollView scrollView = new ScrollView { Content = flexLayout }; // Set the ScrollView as the child of the RefreshView. RefreshView refreshView = new RefreshView { Content = scrollView, RefreshColor = Color.Teal }; refreshView.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing"); refreshView.SetBinding(RefreshView.CommandProperty, "RefreshCommand"); // Build the page. Title = "RefreshView Demo"; BindingContext = viewModel; Content = new StackLayout { Margin = new Thickness(10), Children = { header, pullMessage, numberOfItems, refreshView } }; }
public ReferringSitesPage(ReferringSitesViewModel referringSitesViewModel, Repository repository) : base(PageTitles.ReferringSitesPage, referringSitesViewModel) { var collectionView = new CollectionView { ItemTemplate = new ReferringSitesDataTemplateSelector(), SelectionMode = SelectionMode.Single }; collectionView.SelectionChanged += HandleCollectionViewSelectionChanged; collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.ReferringSitesCollection)); _refreshView = new RefreshView { InputTransparent = true, CommandParameter = (repository.OwnerLogin, repository.Name), Content = collectionView }; _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.RefreshControlColor)); _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand)); _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing)); if (Device.RuntimePlatform is Device.iOS) { var titleLabel = new Label { FontAttributes = FontAttributes.Bold, Text = PageTitles.ReferringSitesPage, FontSize = 30, VerticalTextAlignment = TextAlignment.Center, Margin = new Thickness(10, 0) }; titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); var grid = new Grid { RowDefinitions = { new RowDefinition { Height = new GridLength(50, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; grid.Children.Add(titleLabel, 0, 0); grid.Children.Add(_refreshView, 0, 1); Content = grid; } else { Content = _refreshView; } }