1
votes

In my app there is a certain listview that I use over and over in my app, only with different elements in it. Therefore, I put everything inside a contentview and inflated it in my xaml like so:

<ContentPage Title="Newbies" BackgroundColor="#fafafa">

    <views:CV_AllAdsRes />

</ContentPage>

The class looks like this:

public partial class CV_AllAdsRes : ContentView
    {

        public CV_AllAdsRes(int id)
        {
            InitializeComponent();

            SetAds();
        }

}

Now, this doenst work, because I am not using a "default constructor". If I remove the "int id" from the constructor, it works no problem. But I need to be able to inflate this content view with different parameters inside the xaml.

Am I understanding this concept wrong?

How can I inflate my content view and give it parameters via xaml?

Thank you

1

1 Answers

1
votes

I solved it by using a second constructor next to the default one and giving it arguments from xaml like so:

    <views:CV_AllAdsRes >
        <x:Arguments >
            <x:Int32>5</x:Int32>               
        </x:Arguments>
    </views:CV_AllAdsRes>

this will give ID=5.