public ListViewDemoPage(ListViewCachingStrategy cachingStrategy) { Title = "ListView demos"; Content = new StackLayout { Children = { CreateSubpageButton(new DemoListViewWithTextCell(cachingStrategy) { Header = "plain header", Footer = "plain footer" }), CreateSubpageButton(new DemoListViewWithStringViewCell(cachingStrategy) { Header = new DemoLabel("header label"), Footer = new DemoLabel("footer label") }), CreateSubpageButton(new DemoListViewWithItemViewCell(cachingStrategy)), CreateSubpageButton(new DemoListViewWithGroups(cachingStrategy)), CreateSubpageButton(new DemoListViewWithGroupsAndHeaderTemplate(cachingStrategy)), CreateSubpageButton(new DemoListViewWithGestureRecognizers(cachingStrategy)), CreateSubpageButton(new DemoListViewForRecycling(cachingStrategy)), CreateSubpageButton(new DemoListViewForRecyclingWithTemplateSelector(cachingStrategy)), CreateSubpageButton(new DemoListViewForRecyclingWithGroups(cachingStrategy)), }, }; }
public DemoListViewForRecyclingWithGroups(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <StringGroup> { new StringGroup(new [] { "A4", "B4" }, "Group 4"), new StringGroup(new [] { "A5", "B5" }, "Group 5"), }; ItemTemplate = new DataTemplate(typeof(GroupRecycleCell)); IsGroupingEnabled = true; GroupDisplayBinding = new Binding(nameof(StringGroup.Title)); BackgroundColor = Color.GhostWhite; Label header; Header = header = new Label() { Text = "Reverse" }; header.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(o => { ItemsSource = (ItemsSource as IEnumerable <StringGroup>) .Reverse() .Select(sg => new StringGroup((sg as IEnumerable <string>).Reverse(), sg.Title)) .ToList(); }) }); // Reset instance count for each test GroupRecycleCell.InstanceCount = 0; }
public ListView([Parameter("CachingStrategy")] ListViewCachingStrategy cachingStrategy) : this() { if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS) { CachingStrategy = cachingStrategy; } }
public ListView([Parameter("CachingStrategy")] ListViewCachingStrategy cachingStrategy) : this() { if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.macOS) { CachingStrategy = cachingStrategy; } }
public ModListView(ListViewCachingStrategy strategy) : base(strategy) { InitializeComponent(); ItemSelected += (sender, e) => SelectedItem = null; }
public override AView GetView(int position, AView convertView, ViewGroup parent) { Cell cell = null; Performance.Start(out string reference); ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy; var nextCellIsHeader = false; if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null) { if (_listView.IsGroupingEnabled) { List <Cell> cells = GetCellsFromPosition(position, 2); if (cells.Count > 0) { cell = cells[0]; } if (cells.Count == 2) { nextCellIsHeader = cells[1].GetIsGroupHeader <ItemsView <Cell>, Cell>(); } } if (cell == null) { cell = GetCellForPosition(position); if (cell == null) { return(new AView(_context)); } } } var cellIsBeingReused = false; var layout = convertView as ConditionalFocusLayout; if (layout != null) { cellIsBeingReused = true; convertView = layout.GetChildAt(0); } else { layout = new ConditionalFocusLayout(_context) { Orientation = Orientation.Vertical }; _layoutsCreated.Add(layout); } if (((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) && convertView != null) { var boxedCell = convertView as INativeElementView; if (boxedCell == null) { throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling."); } cell = (Cell)boxedCell.Element;
public ExtendedListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { this.ItemSelected += OnItemSelected; this.ItemTapped += OnItemTapped; this.ItemAppearing += OnItemAppearing; this.ItemDisappearing += OnItemDisappering; }
public DataGrid(ListViewCachingStrategy cachingStrategy) { InitializeComponent(); _sortingOrders = new Dictionary <int, SortingOrder>(); _listView = new ListView(cachingStrategy) { BackgroundColor = Color.Transparent, ItemTemplate = new DataGridRowTemplateSelector(), SeparatorVisibility = SeparatorVisibility.None, }; _listView.ItemSelected += (s, e) => { if (SelectionEnabled) { SelectedItem = _listView.SelectedItem; } else { _listView.SelectedItem = null; } ItemSelected?.Invoke(this, e); }; _listView.Refreshing += (s, e) => { Refreshing?.Invoke(this, e); }; _listView.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this)); Grid.SetRow(_listView, 1); Children.Add(_listView); }
public DeselectListView(ListViewCachingStrategy strategy) : base(strategy) { ItemTapped += (args, sender) => { SelectedItem = null; }; }
public ItemsView(ListViewCachingStrategy cachingStrategy) : this() { if ((Device.OS == TargetPlatform.Android) || (Device.OS == TargetPlatform.iOS)) { this.CachingStrategy = cachingStrategy; } }
public override AView GetView(int position, AView convertView, ViewGroup parent) { Cell cell = null; Performance.Start(out string reference); ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy; var nextCellIsHeader = false; if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null) { if (_listView.IsGroupingEnabled) { List <Cell> cells = GetCellsFromPosition(position, 2); if (cells.Count > 0) { cell = cells[0]; } if (cells.Count == 2) { nextCellIsHeader = cells[1].GetIsGroupHeader <ItemsView <Cell>, Cell>(); } } if (cell == null) { cell = GetCellForPosition(position); if (cell == null) { Performance.Stop(reference); return(new AView(_context)); } } } var cellIsBeingReused = false; var layout = convertView as ConditionalFocusLayout; if (layout != null) { cellIsBeingReused = true; convertView = layout.GetChildAt(0); _layoutsCreated[position] = layout; } else { // This means the cell was already created during the measuring phase // so we just reuse the layout already created for the cell // This only ever happens if the ListView is forced to measure itself because // it has infinite height if (convertView == null && cell.Handler?.PlatformView is AView aView && aView.Parent is ConditionalFocusLayout cfl) { layout = cfl; }
void InitTest(ListViewCachingStrategy cachingStrategy, bool useTemplate) { List <GroupedData> groups = GetGroups(); var listView = new ListView(cachingStrategy) { ItemsSource = groups, ItemTemplate = new DataTemplate(typeof(MyCell)), HasUnevenRows = true, // Must be grouped to repro IsGroupingEnabled = true }; if (useTemplate) { listView.GroupHeaderTemplate = new DataTemplate(typeof(HeaderCell)); } else { listView.GroupDisplayBinding = new Binding(nameof(GroupedData.GroupName)); } // Must attach to the ListView's events to repro listView.ItemAppearing += ListView_ItemAppearing; listView.ItemDisappearing += ListView_ItemDisappearing; var horStack = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { _scroll, listView }, HeightRequest = 300 }; Button nextButton = new Button { Text = "Next", AutomationId = TestButtonId }; nextButton.Clicked += NextButton_Clicked; StackLayout stack = new StackLayout { Children = { new Label { Text = Instructions }, _groupsAppearing, _groupsDisappearing, horStack, nextButton } }; Content = stack; var lastGroup = groups.Last(); var lastItem = lastGroup.First(); var firstGroup = groups.First(); var firstItem = firstGroup.First(); Device.StartTimer(TimeSpan.FromSeconds(1), () => { listView.ScrollTo(lastItem, lastGroup, ScrollToPosition.End, true); return(false); }); Device.StartTimer(TimeSpan.FromSeconds(2), () => { listView.ScrollTo(firstItem, firstItem, ScrollToPosition.MakeVisible, true); return(false); }); _TestNumber++; }
/// <summary> /// Initializes a new instance of the <see cref="T:AiForms.Renderers.CollectionView"/> class. /// </summary> /// <param name="cachingStrategy">Caching strategy.</param> public CollectionView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ScrollController = new ScrollController(this); SetLoadMoreCompletion = (isEnd) => { SetLoadMoreCompletionAction?.Invoke(isEnd); }; }
Button GetButton <T>(ListViewCachingStrategy strategy) where T : Cell { return(new Button { Text = $"{typeof(T).Name} {strategy}", Command = new Command(async() => await Navigation.PushAsync(new MyPage <T>(strategy))) }); }
public ListView([Parameter("CachingStrategy")] ListViewCachingStrategy cachingStrategy) : this() { // null => UnitTest "platform" if (Device.RuntimePlatform == null || Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.macOS) CachingStrategy = cachingStrategy; }
public InfiniteListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { _keyboardHelper = FreshIOC.Container.Resolve <IKeyboardHelper>(); _gestureDismiss = new TapGestureRecognizer { Command = new Command(() => _keyboardHelper.HideKeyboard()) }; }
public DemoListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { // ListView ignores caching stragey on platforms where recycling is not supported. // ListView will use caching strategy when runtimePlatform is null ("unit test mode"), // which can be set when initialising Xamarin.Forms.Mocks. if (CachingStrategy != cachingStrategy) { throw new ArgumentException("Caching strategy must not be ignored."); } }
/// <include file="../../docs/Microsoft.Maui.Controls/ListView.xml" path="//Member[@MemberName='.ctor']/Docs" /> public ListView([Parameter("CachingStrategy")] ListViewCachingStrategy cachingStrategy) : this() { // Unknown => UnitTest "platform" if (DeviceInfo.Platform == DevicePlatform.Unknown || DeviceInfo.Platform == DevicePlatform.Android || DeviceInfo.Platform == DevicePlatform.iOS || DeviceInfo.Platform == DevicePlatform.macOS) { CachingStrategy = cachingStrategy; } }
static CrawlingStrategy GetCrawlingStrategy(ListViewCachingStrategy cachingStrategy) { if ((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) { return(recycleStrategy); } else { return(retainStrategy); } }
public MyPage(ListViewCachingStrategy strategy) { _DataSource = Enumerable.Range(0, 10).Select(n => new VariableHeightItem()).ToList(); var listView = new ListView(strategy) { HasUnevenRows = true, ItemsSource = _DataSource, ItemTemplate = new DataTemplate(typeof(T)) }; var button = new Button { Text = "Click me" }; button.Clicked += async(sender, e) => { for (int i = 0; i < _DataSource.Count; i++) { var target = _DataSource[i]; if (DeviceInfo.Platform == DevicePlatform.iOS) { if (typeof(T) == typeof(MyViewCell)) { target.Text = "I am an exceptionally long string that should cause the label to wrap, thus increasing the size of the cell such that the entirety of the string is readable by human eyes. Hurrah."; } else if (strategy == ListViewCachingStrategy.RetainElement) { target.Text = "Look, I'm taller!"; } else { target.Text = $"I'm only taller in {ListViewCachingStrategy.RetainElement} mode. :("; } } else { if (typeof(T) == typeof(MyViewCell)) { target.Text = "I am an exceptionally long string that should cause the label to wrap, thus increasing the size of the cell such that the entirety of the string is readable by human eyes. Hurrah."; } else { target.Text = "Look, I'm taller!"; } } await Task.Delay(1000); } }; Content = new StackLayout { Children = { button, listView } }; Title = $"{typeof(T).Name} {strategy}"; }
public DemoListViewWithStringViewCell(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <string> { "Item A2", "Item B2", "Item C2" }; ItemTemplate = new DataTemplate(typeof(StringDemoCell)); BackgroundColor = Color.GhostWhite; HeightRequest = 200; ItemTapped += (sender, e) => App.ShowMessage("Success", e.Item + " tapped"); }
public DemoListViewWithTextCell(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <string> { "Item A1", "Item B1", "Item C1" }; ItemTemplate = new DataTemplate(typeof(TextCell)); BackgroundColor = Color.GhostWhite; ItemTemplate.SetBinding(TextCell.TextProperty, "."); ItemTapped += (sender, e) => App.ShowMessage("Success", e.Item + " tapped"); }
public InfiniteListView(ListViewCachingStrategy strategy) : base(strategy) { try { ItemAppearing += InfiniteListView_ItemAppearing; ItemTapped += InfiniteListView_OnItemTapped; } catch (System.Exception ex) { } }
public DemoListViewWithGestureRecognizers(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <Item> { new Item { Name = "Item" } }; ItemTemplate = new DataTemplate(typeof(ItemGestureCell)); BackgroundColor = Color.GhostWhite; ItemTapped += (sender, e) => App.ShowMessage("ListView Cell", (e.Item as Item).Name + " tapped"); }
public DemoListViewWithGroupsAndHeaderTemplate(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <List <string> > { new StringGroup(new [] { "A6", "B6", "C6" }, "Group 6"), new StringGroup(new [] { "A7", "B7", "C7" }, "Group 7"), }; ItemTemplate = new DataTemplate(typeof(StringDemoCell)); IsGroupingEnabled = true; GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderCell)); BackgroundColor = Color.GhostWhite; ItemTapped += (sender, e) => App.ShowMessage("Success", (e.Item as string) + " tapped"); }
public DemoListViewWithGroups(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <List <string> > { new StringGroup(new [] { "A4", "B4", "C4" }, "Group 4"), new StringGroup(new [] { "A5", "B5", "C5" }, "Group 5"), }; ItemTemplate = new DataTemplate(typeof(StringDemoCell)); IsGroupingEnabled = true; GroupDisplayBinding = new Binding(nameof(StringGroup.Title)); BackgroundColor = Color.GhostWhite; ItemTapped += (sender, e) => App.ShowMessage("Success", (e.Item as string) + " tapped"); }
public ListViewCustomCellPage(ListViewCachingStrategy strategy) { DataTemplate it = new DataTemplate(typeof(CustomCell)); it.SetBinding(CustomCell.TextProperty, "Title"); it.SetBinding(CustomCell.DetailProperty, "SubTitle"); ListView listV = new ListView(strategy) { HasUnevenRows = true, ItemTemplate = it, ItemsSource = GetData() }; Content = listV; }
public DemoListViewWithItemViewCell(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { ItemsSource = new List <Item> { new Item { Name = "Item A3" }, new Item { Name = "Item B3" }, new Item { Name = "Item C3" } }; ItemTemplate = new DataTemplate(typeof(ItemDemoCell)); BackgroundColor = Color.GhostWhite; ItemTapped += (sender, e) => App.ShowMessage("Success", (e.Item as Item).Name + " tapped"); }
public BsdListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { this.ItemAppearing += OnItemAppearing; this.ItemTapped += OnItemTapped; this.IsPullToRefreshEnabled = true; this.HasUnevenRows = true; this.SelectionMode = ListViewSelectionMode.None; this.SeparatorVisibility = SeparatorVisibility.None; this.BackgroundColor = Color.FromHex("#eeeeee"); this.SetBinding(RefreshCommandProperty, new Binding("RefreshCommand")); this.SetBinding(IsRefreshingProperty, new Binding("IsRefreshing")); this.SetBinding(ItemsSourceProperty, new Binding("Data")); InfiniteScrollBehavior behavior = new InfiniteScrollBehavior(); behavior.SetBinding(InfiniteScrollBehavior.IsLoadingMoreProperty, new Binding("IsBusy")); this.Behaviors.Add(behavior); }
public PageableListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { _loadingActivityIndicator = new ActivityIndicator { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Color = Color.Gray, IsRunning = true, IsVisible = false }; var busyIndicatorContainer = new Grid(); busyIndicatorContainer.Children.Add(_loadingActivityIndicator, 0, 0); Footer = busyIndicatorContainer; ItemAppearing += OnItemAppearing; ItemSelected += OnItemSelected; }
public ExtendedListView(ListViewCachingStrategy strategy) : base(strategy) { }
/// <summary> /// Initializes a new instance of the <see cref="T:DLToolkit.Forms.Controls.FlowListView"/> class. /// </summary> /// <param name="cachingStrategy">Caching strategy.</param> public FlowListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { InitialSetup(); }
public AlternatingListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { }