xamarin/Xamarin.Forms

Label's Text value becomes null when used Triggers after updating its value through BindingContext

开放

#3,826 创建于 2018年9月19日

 (12 条评论) (2 个反应) (0 位负责人)C# (1,926 个派生)batch import
e/4 :clock4:help wantedpartnert/bug :bug:up-for-grabs

仓库指标

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

描述

Hi Team,

Description

We have made a custom control to reuse the items in the View by updating only their BindingContext i.e., Similar to XForms ListView CachingStrategy-RecycleElement. When used Triggers for Label element inside the ItemTemplate of the custom control, we have noticed some odd behavior. We have used 2 DataTriggers for a single Label element and applied Setter for Label's Text, TextColor and BackgroundColor properties. This DataTrigger will be chosen based on the Model bool value[In our case we have considered 'Favorite' value]. For the first DataTrigger, we have directly used string value for Label's Text and for second DataTrigger, we have bound the string property from model class. Initially when the View is loaded, everything works fine and the items are layout based on the trigger values. But while scrolling, i.e., when the BindingContext gets updated for the item to be appeared in the view, the static Text value becomes 'null'. This is the issue, we are facing currently. We have checked whether the triggers values have been reset or wrong BindingContext has been set for the item. But still everything works fine and the trigger value for this condition is still maintained. The same template works fine when using XForms ListView with RecycleElement. Another strange thing is that the Color attributes which we have used[FontColor and BackgroundColor] have been updated properly while scrolling! To add up some weirdness, alternating the position of both the triggers works fine while scrolling!! This issue is notable in UWP and iOS platforms. This template doesn't work in Android platform[Even when replaced custom control with XForms ListView] which is another issue.

Steps to Reproduce

  1. Run the attached sample.
  2. In UWP, Scroll up and down the list faster. In Android, the View is empty, still the list is scroll-able[same behavior with XForms ListView]. In iOS, just scroll down the list.

Expected Behavior

While scrolling Label elements should render properly based on the trigger value specified. In android platform, the label elements should render in the View when applied triggers.

Actual Behavior

Notice that the text 'This disappears on scrolling' disappears in UWP and iOS platform. In android, label is entirely invisible.

Reproduction Link

Please find the issue replicating sample with the video cast to showcase the issue in the below link.

TriggerIssue.zip

贡献者指南