Forum Xamarin.Forms

Using custom view in .xaml file - Pass values to custom view

neblazneblaz DEMember ✭✭

Couldn't find so far an example which I could understand.

I have a custom view like:

public class CustomViewLabel : StackLayout
{
    public string TextProp {
        get; set;
    }

    public CustomViewLabel()
    {
        create();
    }

    public void create()
    {
        Label lbl = new Label();
        lbl.Text = TextProp;
        Children.Add(lbl);
    }
}

In the .xaml file I want to use it like:

... <local:CustomViewLabel TextProp="Hello World!"/> ...

When I set a breakpoint in the create() method, the value for TextProp is null.

As only a parameter-less constructor can be used, how to pass values to the custom control?

Sign In or Register to comment.