void SwitchLayouts(LayoutType layoutType) { if (layoutType == LayoutType.ListLayout) { if (listView == null) { listView = new ListView { BackgroundColor = Color.White, HasUnevenRows = true, ItemTemplate = new DataTemplate (typeof(NewsLetterCellTemplate)), SeparatorColor = Color.Transparent, }; listView.ItemsSource = ViewModel.Files; listView.BackgroundColor = Color.Transparent; listView.ItemTapped += (sender, e) => { ((ListView)sender).SelectedItem = null; }; listView.ItemSelected += (sender, e) => { if (e.SelectedItem == null) return; var currentItem = (ProductCatalog)e.SelectedItem; var page = new DetailsPopup (currentItem, LibraryType.NewsLetter); this.Navigation.PushAsync (page, false); }; } Device.OnPlatform ( iOS: () => { grid = new Grid { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }, } }; }, Android: () => { grid = new Grid { VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.Center, RowDefinitions = { new RowDefinition { Height = new GridLength (1, GridUnitType.Star) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }, } }; }, WinPhone: () => { grid = new Grid { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }, } }; } ); grid.Children.Add (listView, 0, 0); grid.Children.Add (CreateLoadingIndicator (), 0, 0); grid.Children.Add (ShowEmptyResults (), 0, 0); this.Content = grid; } else { if (imageGrid == null) { Device.OnPlatform (iOS: () => { imageGrid = new GridView { RowSpacing = 5, Padding = 5, ColumnSpacing = 5, WidthRequest = App.ScreenWidth - 20, HeightRequest = App.ScreenHeight, ItemWidth = UIConstants.GetGridViewItemWidths (), ItemHeight = UIConstants.GetGridViewItemHeights (), ItemsSource = ViewModel.ImageFiles, ItemTemplate = new DataTemplate (typeof(GridViewCellTemplate)), }; }, Android: () => { imageGrid = new GridView { Padding = 20, RowSpacing = 20, ColumnSpacing = 20, ItemWidth = 500, ItemHeight = 732, ItemsSource = ViewModel.ImageFiles, ItemTemplate = new DataTemplate (typeof(DynamicNewsLetterTemplateLayout)), IsClippedToBounds = true, }; }); imageGrid.ItemSelected += (sender, e) => { var currentItem = (ProductCatalog)e.Value; var fileItem = ViewModel.Files.ToList ().FirstOrDefault (i => i.Id == currentItem.Id); var page = new DetailsPopup (fileItem, LibraryType.NewsLetter); Navigation.PushAsync (page, true); }; } grid = new Grid { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }, } }; grid.Children.Add (imageGrid, 0, 0); grid.Children.Add (CreateLoadingIndicator (), 0, 0); grid.Children.Add (ShowEmptyResults (), 0, 0); this.Content = grid; } }
public SearchView(LibraryType type) { //this.BackgroundImage = ImageConstants.backgroundImage; BindingContext = new SearchViewModel (); categoryType = type; var searchBar = new SearchBar (); searchBar.SearchButtonPressed += OnSearchBarButtonPressed; searchBar.TextChanged += (sender, e) => { //var changedSearchBar = (SearchBar)sender; if (e.NewTextValue == null) { //this only happens when user taps "Cancel" on iOS ViewModel.LoadItemsCommand.Execute (null); searchlistView.ItemsSource = ViewModel.SearchItems; searchlistView.IsVisible = true; resultlistView.IsVisible = false; } }; searchlistView = new ListView () { HasUnevenRows = true, ItemTemplate = new DataTemplate (typeof(SearchItemTemplate)), SeparatorColor = Color.Transparent, BackgroundColor = Color.Transparent, }; resultlistView = new ListView () { HasUnevenRows = true, ItemTemplate = new DataTemplate (typeof(ResultsItemTemplate)), //SeparatorColor = Color.Transparent, BackgroundColor = Color.Transparent, }; searchlistView.ItemTapped += (sender, e) => { var search = (Search)e.Item; ViewModel.SearchText = search.SearchText; if(categoryType != LibraryType.MyDocuments){ ViewModel.LoadResultsCommand.Execute (null); resultlistView.ItemsSource = ViewModel.Files; } else{ ViewModel.LoadDownloadedSearchResultsCommand.Execute (null); resultlistView.ItemsSource = ViewModel.DownloadedFiles; } searchlistView.IsVisible = false; resultlistView.IsVisible = true; }; resultlistView.ItemTapped += (sender, e) => { if(categoryType == LibraryType.MyDocuments){ var fileItem = (Downloads)e.Item; var page = new DocumentDetails (fileItem); this.Navigation.PushAsync (page,true); } else{ var fileItem = (ProductCatalog)e.Item; var page = new DetailsPopup (fileItem,type); this.Navigation.PushAsync (page,true); } }; Content = new PopupLayout { //VerticalOptions = LayoutOptions.Center, Content = new StackLayout { //BackgroundColor = Color.Black, Children = { searchBar, searchlistView, resultlistView } } }; resultlistView.IsVisible = false; Title = Translation.Localize("SearchLabel"); }
protected override void OnBindingContextChanged() { base.OnBindingContextChanged (); dynamic c = BindingContext; // TODO: Fix book item vertical scroll issue - RowHeight - 1 = No Scroll var itemView = new ListView { //BackgroundColor = Color.Lime, ItemsSource = new List<dynamic> { c }, ItemTemplate = new DataTemplate (typeof(ListTemplateLayout)), HasUnevenRows = false, IsPullToRefreshEnabled = false, HeightRequest = 244, VerticalOptions = LayoutOptions.FillAndExpand, SeparatorVisibility = SeparatorVisibility.None, InputTransparent = true, RowHeight = 243 }; itemView.ItemTapped += (sender, e) => { ((ListView)sender).SelectedItem = null; }; itemView.ItemSelected += (sender, e) => { if (e.SelectedItem == null) return; var currentItem = (ProductCatalog)e.SelectedItem; var page = new DetailsPopup (currentItem, LibraryType.NewsLetter); NewsletterView.Instance.Navigation.PushAsync (page, false); }; View = itemView; }