First, I should explain what I'm trying to accomplish in case there is another way.
I want to create a resusable component (i.e. a contentview) which is basically a listview with templates and some functionality baked in.
I do want the user of this component to be able to specify a header if desired so I thought it would be easy enough to add 2 properties to the compent: HeaderTemplate and Header
public static readonly BindableProperty HeaderTemplateProperty = BindableProperty.Create<Articles, DataTemplate>(a => a.HeaderTemplate, null);
public static readonly BindableProperty HeaderProperty = BindableProperty.Create<Articles, object>(a => a.Header, null);
public DataTemplate HeaderTemplate
{
get
{
return (DataTemplate)this.GetValue(HeaderTemplateProperty);
}
set
{
this.SetValue(HeaderTemplateProperty, value);
}
}
public object Header
{
get
{
return this.GetValue(HeaderProperty);
}
set
{
this.SetValue(HeaderProperty, value);
}
}
In my xaml I bind the ListView properties to these properties:
<ListView
ItemsSource="{Binding Source}"
Header="{Binding Header}"
HeaderTempate="{Binding HeaderTemplate}">
...
</ListView>
This works perfectly in windows phone.. I can specify my own values for these properties in the consumer of my component. In iOS.. no such luck.. it doesn't display a header at all
Why is this?
I think it's because in the ListViewRenderer for windows phone we have:
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
....
else if (e.PropertyName == "HeaderElement")
this.UpdateHeader();
....
Nothing similar exists in the iOS renderer.. all the header template stuff happens in the OnElementChanged method (i.e. it just runs once when the element is set)
What about android? I don't know. I'm not developing for android and don't have a license to do so.
Finally, please let me know if this information is useful. I've reported a few other bugs in both the forums and in bugzilla but I've not got any acknowledgement of them from anyone at xamarin (although confirmation from other community members).