Xamarin.forms: [iOS] ViewCell not rendered properly when binding to own property

Created on 23 May 2018  ·  11Comments  ·  Source: xamarin/Xamarin.Forms

Description

When creating a custom ViewCell with a bindable property, and one of the child controls binds to that property of the custom ViewCell, the control is not properly rendered on iOS (size of the control is not updated). It works as expected on Android and UWP.

This is a regression in 3.0, because it worked fine on all platforms in previous versions of Xamarin.Forms

Steps to Reproduce

Create a custom ViewCell, with a bindable property for example:

public partial class MyCell
{
    public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(MyCell), string.Empty);

    public string Text
    {
        get => (string) GetValue(TextProperty);
        set => SetValue(TextProperty, value);
    }

    public MyCell ()
    {
        InitializeComponent ();
    }
}

XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BugCellView.MyCell"
             x:Name="Self"
          >
      <StackLayout Padding="5">
          <Label Text="{Binding Text, Source={x:Reference Self}}" />
      </StackLayout>
</ViewCell>

The label defined in the ViewCell references the bindable property "Text" of MyCell

When this custom viewcell is used in a listview on iOS, the label is updated correctly, but the size of the label is not changed. This is the result on iOS:

screenshot

When scrolling the listview a little, the cells that were scrolled off screen and back in view are rendered properly:

simulator screen shot - iphone 8 - 2018-05-22 at 16 43 12

This worked fine in Xamarin Forms 2.5 and earlier. It also works fine with Xamarin Forms 3.0 on Android and UWP

Basic Information

  • Version with issue: 3.0.0.482510
  • Last known good version: 2.5
  • IDE: VS 2017
  • Platform Target Frameworks:

    • iOS: 11.3

    • Android: 8.1 (SDK 27)

    • UWP: 1703

Reproduction Link

Minimal test project, 100% reproduceable:

BugCellView.zip

layout listview 5 help wanted inactive iOS 🍎 needs-info ❓ bug up-for-grabs

Most helpful comment

@samhouts I don't remember if I tried that, but it's not a solution to the problem. It's not just a resizing issue. Binding anything to ViewCell properties is seriously broken on all platforms. I will try to create a repro that shows the full extent of the problem.

All 11 comments

@activa

Was this on the latest version of 2.5 you said it was working? I tested your code against 2.5 and 3.0 and both have the same result

image

To be honest, I didn't test the repro on XF 2.5, but the reason I started investigating this was that this issue appeared in our app after upgrading to XF 3.0. So I assumed it was something that was introduced in 3.0

Yea it looks like when going through a bindable object like that it renderers the rows as the empty value first which is how it gets measured. Binding against a ViewModel it measures out correctly

If you can isolate what was working in 2.5 and what broke in 3.0 that would be helpful.

Looks like it didn't work in earlier versions either. Right before we upgraded to XF 3.0, I made a few small changes to eliminate boilerplate code (such as making use of bindings in XAML instead of setting properties in code). Those changes exposed this bug but I didn't catch it at the time because it wasn't immediately obvious in most cases.

This issue seems no longer limited to iOS. In a ViewCell, binding to a property of the ViewCell itself doesn't work on any platform. It works on all other views, but not for ViewCells.

@samhouts I don't remember if I tried that, but it's not a solution to the problem. It's not just a resizing issue. Binding anything to ViewCell properties is seriously broken on all platforms. I will try to create a repro that shows the full extent of the problem.

I can confirm there is a bug with ListView and ViewCell Binding.

I have a viewcell with Bindable properties in the code behind, with a callback on OnPropertyChanging. Sometimes it fires, sometimes it does not and I can't figured out what's going on as it is randomly bugging/working. On the contrary, Binding outside a viewcell is always working ...

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

@samhouts I have tested this on XF 4.8 and the issue is no longer reproducible.

HOORAY! Thank you @activa !!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

suihanhbr picture suihanhbr  ·  3Comments

MartinWegner picture MartinWegner  ·  3Comments

deakjahn picture deakjahn  ·  3Comments

EmilAlipiev picture EmilAlipiev  ·  3Comments

jgold6 picture jgold6  ·  3Comments