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

Custom BindableProperty - what am I doing wrong?

$
0
0

Hello,

I have a custom ViewCell subclass called MessageDetailCell that I am using to display text messages in a ListView. I been successfully binding properties of the various child views (Label.TextProperty etc) but I am having trouble with a custom BindableProperty. Here is how it's defined in my subclass:

public static readonly BindableProperty ItemTypeProperty = BindableProperty.Create<MessageDetailCell, string>(p => p.ItemType, default(string), BindingMode.OneWay);
    /// <summary>
    /// Gets or sets the item type
    /// </summary>
    public string ItemType
    {
        get {
            Debug.WriteLine("GETTING ItemType property");
            return (string)GetValue(ItemTypeProperty);
        }
        set {
            Debug.WriteLine("SETTING ItemType property");
            SetValue(ItemTypeProperty, value);
        }
    }

In the constructor I am binding it like so:

this.SetBinding(ItemTypeProperty, "item_type");

This doesn't work, and I don't see the debug text output to the console. Yet, when I bind item_type to a Label it displays the value correctly:

subjectLabel.SetBinding(Label.TextProperty, "item_type");

What am I missing?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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