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

How to supply a Xamarin.Form DataTemplate within a Custom Renderer to a native control

$
0
0

Hi there,

I was hoping to implement a custom renderer for a HorizontalListView.

Ive added two properties to the HorizontalListView; ItemsSource and ItemTemplate.

In the customer renderer for this view I was hoping to be able to set the DataTemplate for a native ListBox control (windows phone)

I tried following custom renderer hoping that it would just work but unfortunately it doesn't seen to. Can you advise whether this should be possible (or not) and whether this is the right way to go about providing a Xamarin.Forms DataTemplate to a native control.

Thanks.
Stuart

public class HorizontalListViewRenderer : ViewRenderer
{
    protected override void OnModelSet()
    {
        base.OnModelSet();
        var model = Model as HorizontalListView;
        var listBox = new ListBox();
        listBox.ItemTemplate = new ViewCellRenderer().GetTemplate((Cell)model.ItemTemplate.CreateContent());
        listBox.ItemsSource = model.ItemsSource;
        Children.Add(listBox);
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles



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