diff options
Diffstat (limited to 'Xamarin.Forms.Platform.WP8/ListViewRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WP8/ListViewRenderer.cs | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/Xamarin.Forms.Platform.WP8/ListViewRenderer.cs b/Xamarin.Forms.Platform.WP8/ListViewRenderer.cs index e505526b..538c529f 100644 --- a/Xamarin.Forms.Platform.WP8/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.WP8/ListViewRenderer.cs @@ -11,6 +11,8 @@ using Microsoft.Phone.Controls; using GestureEventArgs = System.Windows.Input.GestureEventArgs; using SLButton = System.Windows.Controls.Button; using SLBinding = System.Windows.Data.Binding; +using System.Collections; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.WinPhone { @@ -192,6 +194,8 @@ namespace Xamarin.Forms.Platform.WinPhone System.Windows.Controls.ProgressBar _progressBar; ViewportControl _viewport; + IListViewController Controller => Element; + ITemplatedItemsView<Cell> TemplatedItemsView => Element; public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { @@ -224,7 +228,7 @@ namespace Xamarin.Forms.Platform.WinPhone { base.OnElementChanged(e); - Element.ScrollToRequested += OnScrollToRequested; + Controller.ScrollToRequested += OnScrollToRequested; if (Element.SelectedItem != null) _itemNeedsSelecting = true; @@ -232,7 +236,7 @@ namespace Xamarin.Forms.Platform.WinPhone _listBox = new FixedLongListSelector { DataContext = Element, - ItemsSource = Element.TemplatedItems, + ItemsSource = (IList)TemplatedItemsView.TemplatedItems, ItemTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["CellTemplate"], GroupHeaderTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["ListViewHeader"], ListHeaderTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["View"], @@ -461,18 +465,17 @@ namespace Xamarin.Forms.Platform.WinPhone if (Element.IsGroupingEnabled) { - TemplatedItemsList<ItemsView<Cell>, Cell> til = TemplatedItemsList<ItemsView<Cell>, Cell>.GetGroup(cell); - parentCell = til.HeaderContent; + parentCell = cell.GetGroupHeaderContent<ItemsView<Cell>, Cell>(); } _fromNative = cell.BindingContext; if (Element.IsGroupingEnabled) { - Element.NotifyRowTapped(TemplatedItemsList<ItemsView<Cell>, Cell>.GetIndex(parentCell), TemplatedItemsList<ItemsView<Cell>, Cell>.GetIndex(cell)); + Controller.NotifyRowTapped(parentCell.GetIndex<ItemsView<Cell>, Cell>(), cell.GetIndex<ItemsView<Cell>, Cell>(), null); } else - Element.NotifyRowTapped(TemplatedItemsList<ItemsView<Cell>, Cell>.GetIndex(cell)); + Controller.NotifyRowTapped(cell.GetIndex<ItemsView<Cell>, Cell>(), null); } void OnNativeSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -496,22 +499,22 @@ namespace Xamarin.Forms.Platform.WinPhone void OnPullToRefreshCanceled(object sender, EventArgs args) { - if (Element.IsPullToRefreshEnabled && ((IListViewController)Element).RefreshAllowed) + if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed) _progressBar.Visibility = Visibility.Collapsed; } void OnPullToRefreshCompleted(object sender, EventArgs args) { - if (Element.IsPullToRefreshEnabled && ((IListViewController)Element).RefreshAllowed) + if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed) { _progressBar.IsIndeterminate = true; - ((IListViewController)Element).SendRefreshing(); + Controller.SendRefreshing(); } } void OnPullToRefreshStarted(object sender, EventArgs args) { - if (Element.IsPullToRefreshEnabled && ((IListViewController)Element).RefreshAllowed) + if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed) { _progressBar.Visibility = Visibility.Visible; _progressBar.IsIndeterminate = false; @@ -521,7 +524,7 @@ namespace Xamarin.Forms.Platform.WinPhone void OnPullToRefreshStatusUpdated(object sender, EventArgs eventArgs) { - if (Element.IsPullToRefreshEnabled && ((IListViewController)Element).RefreshAllowed) + if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed) _progressBar.Value = Math.Max(0, Math.Min(1, _listBox.PullToRefreshStatus)); } @@ -567,28 +570,30 @@ namespace Xamarin.Forms.Platform.WinPhone double targetHeaderHeight = 0; var templateReusables = new Dictionary<System.Windows.DataTemplate, FrameworkElement>(); + var templatedItems = TemplatedItemsView.TemplatedItems; + var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e; var found = false; if (Element.IsGroupingEnabled) { - for (var g = 0; g < Element.TemplatedItems.Count; g++) + for (var g = 0; g < templatedItems.Count; g++) { if (found) break; - TemplatedItemsList<ItemsView<Cell>, Cell> til = Element.TemplatedItems.GetGroup(g); + var til = templatedItems.GetGroup(g); double headerHeight = GetHeight(templateReusables, Control.GroupHeaderTemplate, til); y += headerHeight; for (var i = 0; i < til.Count; i++) { - Cell cell = til[i]; + Cell cell = til[i] as Cell; double contentHeight = GetHeight(templateReusables, Control.ItemTemplate, cell); - if ((ReferenceEquals(til.BindingContext, e.Group) || e.Group == null) && ReferenceEquals(cell.BindingContext, e.Item)) + if ((ReferenceEquals(til.BindingContext, scrollArgs.Group) || scrollArgs.Group == null) && ReferenceEquals(cell.BindingContext, scrollArgs.Item)) { targetHeaderHeight = headerHeight; targetHeight = contentHeight; @@ -602,13 +607,13 @@ namespace Xamarin.Forms.Platform.WinPhone } else { - for (var i = 0; i < Element.TemplatedItems.Count; i++) + for (var i = 0; i < templatedItems.Count; i++) { - Cell cell = Element.TemplatedItems[i]; + Cell cell = templatedItems[i] as Cell; double height = GetHeight(templateReusables, Control.ItemTemplate, cell); - if (ReferenceEquals(cell.BindingContext, e.Item)) + if (ReferenceEquals(cell.BindingContext, scrollArgs.Item)) { found = true; targetHeight = height; @@ -683,12 +688,12 @@ namespace Xamarin.Forms.Platform.WinPhone void UpdateFooter() { - Control.ListFooter = ((IListViewController)Element).FooterElement; + Control.ListFooter = Controller.FooterElement; } void UpdateHeader() { - Control.ListHeader = ((IListViewController)Element).HeaderElement; + Control.ListHeader = Controller.HeaderElement; } void UpdateIsRefreshing() @@ -701,7 +706,7 @@ namespace Xamarin.Forms.Platform.WinPhone else { _progressBar.IsIndeterminate = false; - _progressBar.Visibility = _listBox.IsInPullToRefresh && Element.IsPullToRefreshEnabled && ((IListViewController)Element).RefreshAllowed ? Visibility.Visible : Visibility.Collapsed; + _progressBar.Visibility = _listBox.IsInPullToRefresh && Element.IsPullToRefreshEnabled && Controller.RefreshAllowed ? Visibility.Visible : Visibility.Collapsed; } } |