diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-08-11 02:31:45 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-08-11 10:31:45 +0100 |
commit | 69e9152f345a4a001282ddf60b19cc0a6b7d05e5 (patch) | |
tree | e513166642a2470e2b13bc43987d89507742afd8 | |
parent | 1823c1ad1463aa30deb289bc9538a68a5316164b (diff) | |
download | xamarin-forms-69e9152f345a4a001282ddf60b19cc0a6b7d05e5.tar.gz xamarin-forms-69e9152f345a4a001282ddf60b19cc0a6b7d05e5.tar.bz2 xamarin-forms-69e9152f345a4a001282ddf60b19cc0a6b7d05e5.zip |
[Win] Set BindingContext for default cell (#289)
* Revise 41205 test case to use binding
* [Win] Set BindingContext for default cell
* [Win] SetInheritedBindingContext for Cell
-rw-r--r-- | Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41205.cs | 11 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/CellControl.cs | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41205.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41205.cs index fe578a39..ce773089 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41205.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41205.cs @@ -10,12 +10,21 @@ namespace Xamarin.Forms.Controls.Issues [Issue(IssueTracker.Bugzilla, 41205, "UWP CreateDefault passes string instead of object")] public class Bugzilla41205 : ContentPage { + public class ViewModel + { + public string Text { get { return "Pass"; } } + } + public class CustomListView : ListView { protected override Cell CreateDefault(object item) { if (item is ViewModel) - return base.CreateDefault("Pass"); + { + var newTextCell = new TextCell(); + newTextCell.SetBinding(TextCell.TextProperty, nameof(ViewModel.Text)); + return newTextCell; + } return base.CreateDefault("Fail"); } } diff --git a/Xamarin.Forms.Platform.WinRT/CellControl.cs b/Xamarin.Forms.Platform.WinRT/CellControl.cs index 66be8262..eb06e688 100644 --- a/Xamarin.Forms.Platform.WinRT/CellControl.cs +++ b/Xamarin.Forms.Platform.WinRT/CellControl.cs @@ -215,32 +215,34 @@ namespace Xamarin.Forms.Platform.WinRT { bool isGroupHeader = IsGroupHeader; DataTemplate template = isGroupHeader ? lv.GroupHeaderTemplate : lv.ItemTemplate; + object bindingContext = newContext; if (template is DataTemplateSelector) { - template = ((DataTemplateSelector)template).SelectTemplate(newContext, lv); + template = ((DataTemplateSelector)template).SelectTemplate(bindingContext, lv); } if (template != null) { cell = template.CreateContent() as Cell; - cell.BindingContext = newContext; } else { IListViewController listViewController = lv; - var defaultContext = newContext; if (isGroupHeader) - defaultContext = listViewController.GetDisplayTextFromGroup(newContext); + bindingContext = listViewController.GetDisplayTextFromGroup(bindingContext); - cell = listViewController.CreateDefaultCell(defaultContext); + cell = listViewController.CreateDefaultCell(bindingContext); } // A TableView cell should already have its parent, // but we need to set the parent for a ListView cell. cell.Parent = lv; + // Set inherited BindingContext after setting the Parent so it won't be wiped out + BindableObject.SetInheritedBindingContext(cell, bindingContext); + // This provides the Group Header styling (e.g., larger font, etc.) when the // template is loaded later. cell.SetIsGroupHeader<ItemsView<Cell>, Cell>(isGroupHeader); |