I have a custom PageRenderer with a layout which include a ListView.
Droid project layout MatchPage.xml:
<android.support.design.widget.CoordinatorLayout
[...]
<ListView
android:id="@+id/scrollableview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
[...]
</android.support.design.widget.CoordinatorLayout
Droid project custom renderer:
[assembly: ExportRenderer(typeof(MatchPage), typeof(MatchPageRenderer))]
namespace beSupporter.Droid.Renderers
{
public class MatchPageRenderer : PageRenderer
{
Activity activity;
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
activity = this.Context as Activity;
activity.SetContentView(Resource.Layout.MatchPage);
var listView = (Android.Widget.ListView) this.FindViewById(Resource.Id.scrollableview);
// HERE SET THE SOURCE
}
}
}
How to set the source of the listView if a have in my xamarin.forms ViewModel this property?
public List<Fact> Facts
Usually you don't set source from renderer, I am not sure why you need this. Renderer is used mostly to display things, not to set but if you insist...
In renderer you have access to Element which is your MatchPage. I assume you have your ViewModel as member of the page, so you have access to your list inside the model.