0

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
Longa
  • 364
  • 4
  • 16

1 Answers1

0

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.

Yuri S
  • 5,355
  • 1
  • 15
  • 23
  • Yes, it worked fine. I was able to retrieve viewmodel from the renderer. – Longa Jul 21 '17 at 07:18
  • How did you retrieve the viewmodel? –  Apr 10 '23 at 12:43
  • It is in an answer: 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. – Yuri S Apr 11 '23 at 14:11