Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix 15052 NullReferenceException when returning null from DataTemplateSelector #15074

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7577636
Fix NullReferenceExceptions on null from DataTemplateSelector in Tabb…
bakerhillpins Jan 17, 2022
daaccec
Add DataTemplateSelector tests for null return value.
bakerhillpins Jan 17, 2022
18be4a0
Fix null reference on DataTemplate recycle storage.
bakerhillpins Jan 17, 2022
16c4ea5
Validate BindingContext property set with null Template selected.
bakerhillpins Jan 17, 2022
4fe81b0
Fix CollectionView DataTemplateSelector returns null.
bakerhillpins Jan 18, 2022
2c9325a
iOS, ListView with Recycle, handle DataTemplateSelector return null.
bakerhillpins Jan 18, 2022
8eafd9b
CollectionView DataTemplateSelector returns null for iOS/Tizen/UAP
bakerhillpins Jan 21, 2022
8abeb36
Remove unused DataTemplate code in Flyout.
bakerhillpins Jan 21, 2022
a722a99
Rename only
bakerhillpins Jan 21, 2022
bb6937f
Shell support for DataTemplateSelector returns null
bakerhillpins Jan 21, 2022
686914d
Test for null ItemTemplate and shorten null coalescing statement.
bakerhillpins Jan 21, 2022
295b84d
Move default DataTemplate to single source and update layout to cente…
bakerhillpins Jan 24, 2022
1db1c3e
Use default DataTemplate to create default Page for MultiPage<T> impl…
bakerhillpins Jan 24, 2022
3d72852
Handle null from DataTemplateSelectors.
bakerhillpins Jan 24, 2022
92b0cae
Move default DataTemplate construction into lazy singleton.
bakerhillpins Jan 24, 2022
021ce6b
Adjust method to always return a DataTemplate.
bakerhillpins Jan 24, 2022
8ebc055
Deal with BindableLayout.EmptyViewTemplate selector returning null.
bakerhillpins Jan 25, 2022
74328da
Add support for null from Template Selector
bakerhillpins Jan 26, 2022
f97dfab
Add a simple can return null test.
bakerhillpins Jan 26, 2022
e6cda2a
Merge remote-tracking branch 'origin/5.0.0' into fix-15052
bakerhillpins Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move default DataTemplate construction into lazy singleton.
bakerhillpins committed Jan 24, 2022
commit 92b0caeff1482a0b6449ecbca9459f7eafd5525e
10 changes: 9 additions & 1 deletion Xamarin.Forms.Core/Shell/BaseShellItem.cs
Original file line number Diff line number Diff line change
@@ -330,7 +330,15 @@ BindableObject NonImplicitParent
}
}

internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, string iconBinding)
internal static DataTemplate MenuItemDefaultDataTemplate =
new Lazy<DataTemplate>(
() => CreateDefaultFlyoutItemCell("Text", "Icon") ).Value;

internal static DataTemplate ItemDefaultDataTemplate =
new Lazy<DataTemplate>(
() => CreateDefaultFlyoutItemCell("Title", "FlyoutIcon")).Value;

static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, string iconBinding)
{
return new DataTemplate(() =>
{
13 changes: 5 additions & 8 deletions Xamarin.Forms.Core/Shell/Shell.cs
Original file line number Diff line number Diff line change
@@ -256,21 +256,19 @@ internal static BindableObject GetBindableObjectWithFlyoutItemTemplate(BindableO
DataTemplate IShellController.GetFlyoutItemDataTemplate(BindableObject bo)
{
BindableProperty bp;
string textBinding;
string iconBinding;
DataTemplate defaultTemplate;

var bindableObjectWithTemplate = GetBindableObjectWithFlyoutItemTemplate(bo);

if (bo is IMenuItemController)
{
bp = MenuItemTemplateProperty;
textBinding = "Text";
iconBinding = "Icon";
defaultTemplate = BaseShellItem.MenuItemDefaultDataTemplate;
}
else
{
bp = ItemTemplateProperty;
textBinding = "Title";
iconBinding = "FlyoutIcon";
defaultTemplate = BaseShellItem.ItemDefaultDataTemplate;
}

DataTemplate dataTemplate = (DataTemplate)(bindableObjectWithTemplate.IsSet(bp) ?
@@ -279,8 +277,7 @@ DataTemplate IShellController.GetFlyoutItemDataTemplate(BindableObject bo)
GetValue(bp) :
null);

return dataTemplate?.SelectDataTemplate( bo, this ) ??
BaseShellItem.CreateDefaultFlyoutItemCell(textBinding, iconBinding);
return dataTemplate?.SelectDataTemplate( bo, this ) ?? defaultTemplate;
}

event EventHandler IShellController.StructureChanged