[Bug] Control with DataTemplate can only be added to a page once
#6,476 创建于 2019年6月10日
仓库指标
- 星标
- (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
- Define a control
- Create a Button with a clicked event handler just for testing.
- In the clicked event handler instantiate a DataTemplate with the control
- call
createContentand 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.