Bright Lee
Bright Lee

Reputation: 2316

How to set my custom class's member View's property from XAML? (Xamarin.forms)

I'm making app with using Xamarin.forms.

I already asked question here. How to set child of class' property with using xaml? (Xamarin.forms) But I couldn't get right answer for this, or there may be no solution for that.

What I want to do is setting my class's view's property from ContentPage's XAML. my class has some view like Image and else.

I searched and found that there is 'ControlTemplete'. But I'm not sure it's what I'm looking for.

And I also don't think putting BindableProperty and OnPropertyChangedDelegate codes for every property that I want to set is a best way.

Is there another better solution?

Thanks.

Upvotes: 2

Views: 1238

Answers (1)

root
root

Reputation: 2357

You can map XAML that is inside your control to a property using ContentProperty attribute.

[ContentProperty("MyContent")]
public class MyControl : ContentView 
{
    public View MyContent { get; set; }
}

And in XAML somthing like this

<local:MyControl>
    <Grid></Grid>
</local:MyControl>

this limits you to only one property but should work with any types.

Upvotes: 2

Related Questions