protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == VirtualListView.AdapterProperty.PropertyName) { collectionView.ReloadData(); } else if (e.PropertyName == VirtualListView.SelectionModeProperty.PropertyName) { collectionView.AllowsSelection = Element.SelectionMode != SelectionMode.None; collectionView.AllowsMultipleSelection = Element.SelectionMode == SelectionMode.Multiple; } else if (e.PropertyName == VirtualListView.HeaderTemplateProperty.PropertyName || e.PropertyName == VirtualListView.FooterTemplateProperty.PropertyName || e.PropertyName == VirtualListView.ItemTemplateProperty.PropertyName || e.PropertyName == VirtualListView.ItemTemplateSelectorProperty.PropertyName || e.PropertyName == VirtualListView.SectionFooterTemplateProperty.PropertyName || e.PropertyName == VirtualListView.SectionFooterTemplateSelectorProperty.PropertyName || e.PropertyName == VirtualListView.SectionHeaderTemplateProperty.PropertyName || e.PropertyName == VirtualListView.SectionHeaderTemplateSelectorProperty.PropertyName) { TemplateSelector = CreateTemplateSelector(); DataSource.ResetTemplates(collectionView); collectionView.ReloadData(); collectionView.CollectionViewLayout.InvalidateLayout(); } }
protected override void OnElementChanged(Xamarin.Forms.Platform.UWP.ElementChangedEventArgs <VirtualListView> e) { base.OnElementChanged(e); // Clean up old if (e.OldElement != null) { // Unsubscribe from event handlers and cleanup any resources listView.ChoosingItemContainer -= ListView_ChoosingItemContainer; dataSource.Adapter = null; dataSource.TemplateSelector = null; dataSource = null; templateSelector = null; listView = null; } // Setup new if (e.NewElement != null) { // Create the native control if (Control == null) { listView = new ListView(); templateSelector = CreateTemplateSelector(); dataSource = new UwpDataSource(); dataSource.TemplateSelector = templateSelector; dataSource.Adapter = e.NewElement.Adapter; listView.ItemsSource = dataSource; var style = new Style(typeof(ListView)); listView.Style = style; listView.ItemContainerStyle = new Style(typeof(UwpListViewItem)); listView.ChoosingItemContainer += ListView_ChoosingItemContainer; listView.ContainerContentChanging += ListView_ContainerContentChanging; SetNativeControl(listView); } } }
protected override void OnElementChanged(ElementChangedEventArgs <VirtualListView> e) { base.OnElementChanged(e); // Clean up old if (e.OldElement != null) { } // Setup new if (e.NewElement != null) { TemplateSelector = CreateTemplateSelector(); Adapter = e.NewElement.Adapter; // Create the native control if (Control == null) { layout = new CvLayout(); layout.EstimatedItemSize = UICollectionViewFlowLayout.AutomaticSize; layout.SectionInset = new UIEdgeInsets(0, 0, 0, 0); layout.MinimumInteritemSpacing = 0f; layout.MinimumLineSpacing = 0f; DataSource = new CvDataSource(this); DataSource.IsSelectedHandler = (realSection, realIndex) => e?.NewElement?.IsItemSelected(realSection, realIndex) ?? false; cvdelegate = new CvDelegate(this); collectionView = new UICollectionView(this.Frame, layout); collectionView.AllowsSelection = e.NewElement.SelectionMode != SelectionMode.None; collectionView.AllowsMultipleSelection = e.NewElement.SelectionMode == SelectionMode.Multiple; collectionView.DataSource = DataSource; collectionView.ContentInset = new UIEdgeInsets(0, 0, 0, 0); collectionView.Delegate = cvdelegate; SetNativeControl(collectionView); collectionView.ReloadData(); } } }