diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-06-17 03:10:18 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-06-17 11:10:18 +0100 |
commit | 925fc0aa588a060eb23fa16c1d225dd030012c23 (patch) | |
tree | 83676c25c29d97d9250516b217020ba85425796d /Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs | |
parent | d44396a4534b1e2bc81143c809e4adaee656ab15 (diff) | |
download | xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.gz xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.bz2 xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.zip |
Prep Cell & friends for removal of InternalsVisibleTo (#142)
* Prep Cell & friends for removal of InternalsVisibleTo
Includes:
- Cell
- EntryCell
- ListView
- MenuItem
- TableView
- ViewCell
- Toolbar
Moved extensions to Internal & removed TPH
* Update docs
* [Controls] Ignore Issue2411 on iOS <9
* [Controls] Formatting for Issue2411
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs index d47299a4..c6a9d2db 100644 --- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs @@ -12,6 +12,7 @@ using Windows.UI.Xaml.Media; using WListView = Windows.UI.Xaml.Controls.ListView; using WBinding = Windows.UI.Xaml.Data.Binding; using WApp = Windows.UI.Xaml.Application; +using Xamarin.Forms.Internals; #if WINDOWS_UWP @@ -23,6 +24,10 @@ namespace Xamarin.Forms.Platform.WinRT { public class ListViewRenderer : ViewRenderer<ListView, FrameworkElement> { + IListViewController Controller => Element; + ITemplatedItemsView<Cell> TemplatedItemsView => Element; + + #if !WINDOWS_UWP public static readonly DependencyProperty HighlightWhenSelectedProperty = DependencyProperty.RegisterAttached("HighlightWhenSelected", typeof(bool), typeof(ListViewRenderer), new PropertyMetadata(false)); @@ -47,18 +52,17 @@ namespace Xamarin.Forms.Platform.WinRT if (e.OldElement != null) { e.OldElement.ItemSelected -= OnElementItemSelected; - e.OldElement.ScrollToRequested -= OnElementScrollToRequested; + ((IListViewController)e.OldElement).ScrollToRequested -= OnElementScrollToRequested; } if (e.NewElement != null) { e.NewElement.ItemSelected += OnElementItemSelected; - e.NewElement.ScrollToRequested += OnElementScrollToRequested; + ((IListViewController)e.NewElement).ScrollToRequested += OnElementScrollToRequested; if (List == null) { - List = new WListView - { + List = new WListView { IsSynchronizedWithCurrentItem = false, ItemTemplate = (Windows.UI.Xaml.DataTemplate)WApp.Current.Resources["CellTemplate"], HeaderTemplate = (Windows.UI.Xaml.DataTemplate)WApp.Current.Resources["View"], @@ -214,12 +218,12 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateFooter() { - List.Footer = ((IListViewController)Element).FooterElement; + List.Footer = Controller.FooterElement; } void UpdateHeader() { - List.Header = ((IListViewController)Element).HeaderElement; + List.Header = Controller.HeaderElement; } void UpdateGrouping() @@ -228,13 +232,14 @@ namespace Xamarin.Forms.Platform.WinRT ((CollectionViewSource)List.DataContext).IsSourceGrouped = grouping; - if (grouping && Element.TemplatedItems.ShortNames != null) + var templatedItems = TemplatedItemsView.TemplatedItems; + if (grouping && templatedItems.ShortNames != null) { if (_zoom == null) { ScrollViewer.SetIsVerticalScrollChainingEnabled(List, false); - var grid = new GridView { ItemsSource = Element.TemplatedItems.ShortNames, Style = (Windows.UI.Xaml.Style)WApp.Current.Resources["JumpListGrid"] }; + var grid = new GridView { ItemsSource = templatedItems.ShortNames, Style = (Windows.UI.Xaml.Style)WApp.Current.Resources["JumpListGrid"] }; ScrollViewer.SetIsHorizontalScrollChainingEnabled(grid, false); @@ -269,11 +274,12 @@ namespace Xamarin.Forms.Platform.WinRT // HACK: Technically more than one short name could be the same, this will potentially find the wrong one in that case var item = (string)e.SourceItem.Item; - int index = Element.TemplatedItems.ShortNames.IndexOf(item); + var templatedItems = TemplatedItemsView.TemplatedItems; + int index = templatedItems.ShortNames.IndexOf(item); if (index == -1) return; - TemplatedItemsList<ItemsView<Cell>, Cell> til = Element.TemplatedItems.GetGroup(index); + var til = templatedItems.GetGroup(index); if (til.Count == 0) return; // FIXME @@ -281,7 +287,8 @@ namespace Xamarin.Forms.Platform.WinRT if (Device.Idiom == TargetIdiom.Phone) await Task.Delay(1); - ScrollTo(til.ListProxy.ProxiedEnumerable, til.ListProxy[0], ScrollToPosition.Start, true, true); + IListProxy listProxy = ((ITemplatedItemsView<Cell>)til).ListProxy; + ScrollTo(listProxy.ProxiedEnumerable, listProxy[0], ScrollToPosition.Start, true, true); } #pragma warning disable 1998 // considered for removal @@ -302,12 +309,12 @@ namespace Xamarin.Forms.Platform.WinRT List.Loaded += loadedHandler; return; } - - Tuple<int, int> location = Element.TemplatedItems.GetGroupAndIndexOfItem(group, item); + var templatedItems = TemplatedItemsView.TemplatedItems; + Tuple<int, int> location = templatedItems.GetGroupAndIndexOfItem(group, item); if (location.Item1 == -1 || location.Item2 == -1) return; - object[] t = Element.TemplatedItems.GetGroup(location.Item1).ItemsSource.Cast<object>().ToArray(); + object[] t = templatedItems.GetGroup(location.Item1).ItemsSource.Cast<object>().ToArray(); object c = t[location.Item2]; double viewportHeight = viewer.ViewportHeight; @@ -317,33 +324,33 @@ namespace Xamarin.Forms.Platform.WinRT switch (toPosition) { case ScrollToPosition.Start: - { - List.ScrollIntoView(c, ScrollIntoViewAlignment.Leading); - return; - } + { + List.ScrollIntoView(c, ScrollIntoViewAlignment.Leading); + return; + } case ScrollToPosition.MakeVisible: - { - List.ScrollIntoView(c, ScrollIntoViewAlignment.Default); - return; - } + { + List.ScrollIntoView(c, ScrollIntoViewAlignment.Default); + return; + } case ScrollToPosition.End: case ScrollToPosition.Center: - { - var content = (FrameworkElement)List.ItemTemplate.LoadContent(); - content.DataContext = c; - content.Measure(new Windows.Foundation.Size(viewer.ActualWidth, double.PositiveInfinity)); + { + var content = (FrameworkElement)List.ItemTemplate.LoadContent(); + content.DataContext = c; + content.Measure(new Windows.Foundation.Size(viewer.ActualWidth, double.PositiveInfinity)); - double tHeight = content.DesiredSize.Height; + double tHeight = content.DesiredSize.Height; - if (toPosition == ScrollToPosition.Center) - semanticLocation.Bounds = new Rect(0, viewportHeight / 2 - tHeight / 2, 0, 0); - else - semanticLocation.Bounds = new Rect(0, viewportHeight - tHeight, 0, 0); + if (toPosition == ScrollToPosition.Center) + semanticLocation.Bounds = new Rect(0, viewportHeight / 2 - tHeight / 2, 0, 0); + else + semanticLocation.Bounds = new Rect(0, viewportHeight - tHeight, 0, 0); - break; - } + break; + } } // Waiting for loaded doesn't seem to be enough anymore; the ScrollViewer does not appear until after Loaded. @@ -365,7 +372,8 @@ namespace Xamarin.Forms.Platform.WinRT void OnElementScrollToRequested(object sender, ScrollToRequestedEventArgs e) { - ScrollTo(e.Group, e.Item, e.Position, e.ShouldAnimate); + var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e; + ScrollTo(scrollArgs.Group, scrollArgs.Item, e.Position, e.ShouldAnimate); } T GetFirstDescendant<T>(DependencyObject element) where T : FrameworkElement @@ -428,19 +436,19 @@ namespace Xamarin.Forms.Platform.WinRT List.SelectedIndex = -1; return; } - + var templatedItems = TemplatedItemsView.TemplatedItems; var index = 0; if (Element.IsGroupingEnabled) { - int selectedItemIndex = Element.TemplatedItems.GetGlobalIndexOfItem(e.SelectedItem); + int selectedItemIndex = templatedItems.GetGlobalIndexOfItem(e.SelectedItem); var leftOver = 0; - int groupIndex = Element.TemplatedItems.GetGroupIndexFromGlobal(selectedItemIndex, out leftOver); + int groupIndex = templatedItems.GetGroupIndexFromGlobal(selectedItemIndex, out leftOver); index = selectedItemIndex - (groupIndex + 1); } else { - index = Element.TemplatedItems.GetGlobalIndexOfItem(e.SelectedItem); + index = templatedItems.GetGlobalIndexOfItem(e.SelectedItem); } List.SelectedIndex = index; @@ -459,7 +467,7 @@ namespace Xamarin.Forms.Platform.WinRT if (lv != null) { - index = Element.TemplatedItems.GetGlobalIndexOfItem(lv.Content); + index = TemplatedItemsView.TemplatedItems.GetGlobalIndexOfItem(lv.Content); break; } @@ -488,7 +496,7 @@ namespace Xamarin.Forms.Platform.WinRT } #endif - Element.NotifyRowTapped(index); + Controller.NotifyRowTapped(index, cell: null); #if !WINDOWS_UWP |