xamarin/Xamarin.Forms

[Bug] Control with DataTemplate can only be added to a page once

开放

#6,476 创建于 2019年6月10日

 (5 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
e/5 :clock5:help wantedinactivet/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

When defining a control - and instantiating a new DataTemplate with it new DataTemplate(() => control) in code behind the content created by createContent() can only be added once to the page. If it was already there it won't create a new control object and add it.

Steps to Reproduce

  1. Define a control
  2. Create a Button with a clicked event handler just for testing.
  3. In the clicked event handler instantiate a DataTemplate with the control
  4. call createContent and add the content to the page

Expected Behavior

The control should be added to the page each time the button is clicked.

Actual Behavior

The control will only be added once. If the control was defined in xaml in the page - given to the DataTemplate with x:name- no content created by createContent() gets added.

Basic Information

  • Version with issue: 4.0.0.425677
  • Last known good version: Unknown
  • IDE: Visual Studio Community 2019 (Preview) for Mac Version 8.1 Preview (8.1 build 2697)
  • Platform Target Frameworks:
    • iOS: Version: 12.10.0.153
    • Android: Untested
    • UWP: Untested
  • Android Support Library Version: Not used
  • Nuget Packages: Xamarin.Essentials(1.1.0). Xamarin.Forms(4.0.0.425677)
  • Affected Devices: iPhone 6s simulator. Other not yet tested.

Reproduction Link

https://github.com/Lelelo1/DataTemplateReproduce

More Info

Content created by a DataTemplate that is defined in xaml can successfully be added to the page. The Id in Xamarin.Forms.Element of this content is unique - while for the content from DataTemplate created in code behind - stays the same. It did not help to change the _id field with reflection prior to adding the content to the page.

贡献者指南