Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

What is wrong with the binding in this custom viewcell?

$
0
0

As I have a component i need to show on several listviews, i have extended a viewcell.
I would like to bind the fields in the viewcell to properties in my viewmodels list.

Simplified XAML for HeaderCell:

 <StackLayout x:Name="topBarStackLayout" Orientation="Horizontal">
      <Label x:Name="expiresTimeFieldLabel" TextColor="Red" HorizontalOptions="CenterAndExpand"/>
  </StackLayout>

Simplified CodeBehind for HeaderCell:

public partial class HeaderCell : ViewCell
{
public static BindableProperty ExpiresProperty = BindableProperty.Create(
        propertyName: "expiresTimeFieldLabel",
            returnType: typeof(string),
        declaringType: typeof(HeaderCell),
                defaultValue: "unset",
                defaultBindingMode: BindingMode.OneWay,
                propertyChanged: HandleExpiresChanged);

private static void HandleExpiresChanged(BindableObject bindable, object oldValue, object newValue)
{
        var headerCell = (HeaderCell)bindable;
                string expiresText = (string)newValue;
                headerCell.SetValue(ExpiresProperty, expiresText);
}

Upon debugging I can see that the HandleExpiresChanged method is indeed called, and that the newValue does contain the correct value.
... it just does not make it all the way to the correct label.

Any surgestions?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>