summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-06-17 10:10:18 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-06-17 10:10:18 (GMT)
commit925fc0aa588a060eb23fa16c1d225dd030012c23 (patch)
tree83676c25c29d97d9250516b217020ba85425796d /Xamarin.Forms.Platform.WinRT
parentd44396a4534b1e2bc81143c809e4adaee656ab15 (diff)
downloadxamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.zip
xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.gz
xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.bz2
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')
-rw-r--r--Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs1
-rw-r--r--Xamarin.Forms.Platform.WinRT/CellControl.cs40
-rw-r--r--Xamarin.Forms.Platform.WinRT/EntryCellTextBox.cs2
-rw-r--r--Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs88
-rw-r--r--Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs5
-rw-r--r--Xamarin.Forms.Platform.WinRT/Platform.cs1
-rw-r--r--Xamarin.Forms.Platform.WinRT/TableViewRenderer.cs7
-rw-r--r--Xamarin.Forms.Platform.WinRT/TextCellRenderer.cs5
8 files changed, 70 insertions, 79 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs
index 7fe0ba0..11f4e09 100644
--- a/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/CarouselPageRenderer.cs
@@ -4,6 +4,7 @@ using System.ComponentModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Controls;
+using Xamarin.Forms.Internals;
#if WINDOWS_UWP
diff --git a/Xamarin.Forms.Platform.WinRT/CellControl.cs b/Xamarin.Forms.Platform.WinRT/CellControl.cs
index a47c964..31f2990 100644
--- a/Xamarin.Forms.Platform.WinRT/CellControl.cs
+++ b/Xamarin.Forms.Platform.WinRT/CellControl.cs
@@ -8,6 +8,7 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
+using Xamarin.Forms.Internals;
#if WINDOWS_UWP
@@ -41,7 +42,7 @@ namespace Xamarin.Forms.Platform.WinRT
Unloaded += (sender, args) =>
{
- Cell cell = Cell;
+ ICellController cell = Cell;
if (cell != null)
cell.SendDisappearing();
};
@@ -110,28 +111,6 @@ namespace Xamarin.Forms.Platform.WinRT
return result;
}
- static string GetDisplayTextFromGroup(ListView lv, TemplatedItemsList<ItemsView<Cell>, Cell> group)
- {
- string displayBinding = null;
-
- if (lv.GroupDisplayBinding != null)
- displayBinding = group.Name;
-
- if (lv.GroupShortNameBinding != null)
- displayBinding = group.ShortName;
-
- // TODO: what if they set both? should it default to the ShortName, like it will here?
- // ShortNames binding did not appear to be functional before.
- return displayBinding;
- }
-
- static TemplatedItemsList<ItemsView<Cell>, Cell> GetGroup(object newContext, ListView lv)
- {
- int groupIndex = lv.TemplatedItems.GetGlobalIndexOfGroup(newContext);
- TemplatedItemsList<ItemsView<Cell>, Cell> group = lv.TemplatedItems.GetGroup(groupIndex);
- return group;
- }
-
ListView GetListView()
{
DependencyObject parent = VisualTreeHelper.GetParent(this);
@@ -251,13 +230,12 @@ namespace Xamarin.Forms.Platform.WinRT
{
string textContent = newContext.ToString();
+ IListViewController listViewController = lv;
+
if (isGroupHeader)
- {
- TemplatedItemsList<ItemsView<Cell>, Cell> group = GetGroup(newContext, lv);
- textContent = GetDisplayTextFromGroup(lv, group);
- }
+ textContent = listViewController.GetDisplayTextFromGroup(newContext);
- cell = lv.CreateDefaultCell(textContent);
+ cell = listViewController.CreateDefaultCell(textContent);
}
// A TableView cell should already have its parent,
@@ -266,7 +244,7 @@ namespace Xamarin.Forms.Platform.WinRT
// This provides the Group Header styling (e.g., larger font, etc.) when the
// template is loaded later.
- TemplatedItemsList<ItemsView<Cell>, Cell>.SetIsGroupHeader(cell, isGroupHeader);
+ cell.SetIsGroupHeader<ItemsView<Cell>, Cell>(isGroupHeader);
}
Cell = cell;
@@ -277,12 +255,12 @@ namespace Xamarin.Forms.Platform.WinRT
if (oldCell != null)
{
oldCell.PropertyChanged -= _propertyChangedHandler;
- oldCell.SendDisappearing();
+ ((ICellController)oldCell).SendDisappearing();
}
if (newCell != null)
{
- newCell.SendAppearing();
+ ((ICellController)newCell).SendAppearing();
UpdateContent(newCell);
SetupContextMenu();
diff --git a/Xamarin.Forms.Platform.WinRT/EntryCellTextBox.cs b/Xamarin.Forms.Platform.WinRT/EntryCellTextBox.cs
index e280e18..dd99e7e 100644
--- a/Xamarin.Forms.Platform.WinRT/EntryCellTextBox.cs
+++ b/Xamarin.Forms.Platform.WinRT/EntryCellTextBox.cs
@@ -16,7 +16,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
if (e.Key == VirtualKey.Enter)
{
- var cell = DataContext as EntryCell;
+ var cell = DataContext as IEntryCellController;
if (cell != null)
{
cell.SendCompleted();
diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
index d47299a..c6a9d2d 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
diff --git a/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs b/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs
index 31574b4..6f65f31 100644
--- a/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs
+++ b/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs
@@ -13,6 +13,7 @@ namespace Xamarin.Forms.Platform.WinRT
internal class MenuItemCommand : ICommand
{
readonly MenuItem _menuItem;
+ IMenuItemController Controller => _menuItem;
public MenuItemCommand(MenuItem item)
{
@@ -22,14 +23,14 @@ namespace Xamarin.Forms.Platform.WinRT
public virtual bool CanExecute(object parameter)
{
- return _menuItem.IsEnabled;
+ return Controller.IsEnabled;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
- _menuItem.Activate();
+ Controller.Activate();
}
void OnCanExecuteChanged()
diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs
index 268806a..99e51e4 100644
--- a/Xamarin.Forms.Platform.WinRT/Platform.cs
+++ b/Xamarin.Forms.Platform.WinRT/Platform.cs
@@ -11,6 +11,7 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
+using Xamarin.Forms.Internals;
#if WINDOWS_UWP
using Windows.Foundation;
diff --git a/Xamarin.Forms.Platform.WinRT/TableViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/TableViewRenderer.cs
index c5750c7..6ae92a7 100644
--- a/Xamarin.Forms.Platform.WinRT/TableViewRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/TableViewRenderer.cs
@@ -13,6 +13,7 @@ namespace Xamarin.Forms.Platform.WinRT
public class TableViewRenderer : ViewRenderer<TableView, Windows.UI.Xaml.Controls.ListView>
{
bool _ignoreSelectionEvent;
+ ITableViewController Controller => Element;
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
@@ -25,7 +26,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
if (e.OldElement != null)
{
- e.OldElement.ModelChanged -= OnModelChanged;
+ ((ITableViewController)e.OldElement).ModelChanged -= OnModelChanged;
}
if (e.NewElement != null)
@@ -46,7 +47,7 @@ namespace Xamarin.Forms.Platform.WinRT
Control.SelectionChanged += OnSelectionChanged;
}
- e.NewElement.ModelChanged += OnModelChanged;
+ ((ITableViewController)e.NewElement).ModelChanged += OnModelChanged;
OnModelChanged(e.NewElement, EventArgs.Empty);
}
@@ -73,7 +74,7 @@ namespace Xamarin.Forms.Platform.WinRT
var cell = item as Cell;
if (cell != null)
{
- Element.Model.RowSelected(cell);
+ Controller.Model.RowSelected(cell);
break;
}
}
diff --git a/Xamarin.Forms.Platform.WinRT/TextCellRenderer.cs b/Xamarin.Forms.Platform.WinRT/TextCellRenderer.cs
index 4d04a5e..77f3160 100644
--- a/Xamarin.Forms.Platform.WinRT/TextCellRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/TextCellRenderer.cs
@@ -2,6 +2,7 @@
using System.Windows.Input;
using WDataTemplate = Windows.UI.Xaml.DataTemplate;
using WApplication = Windows.UI.Xaml.Application;
+using Xamarin.Forms.Internals;
#if WINDOWS_UWP
@@ -17,7 +18,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
if (cell.RealParent is ListView)
{
- if (TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cell))
+ if (cell.GetIsGroupHeader<ItemsView<Cell>, Cell>())
return (WDataTemplate)WApplication.Current.Resources["ListViewHeaderTextCell"];
//return (WDataTemplate) WApplication.Current.Resources["ListViewTextCell"];
@@ -40,7 +41,7 @@ namespace Xamarin.Forms.Platform.WinRT
public void Execute(object parameter)
{
- var entryCell = (EntryCell)parameter;
+ var entryCell = (IEntryCellController)parameter;
entryCell.SendCompleted();
}
}