Kiss László
Kiss László

Reputation: 275

ListView error in Xamarin.Forms

I've got a strange problem with the ListView component. I have his XAML:

<ListView Margin="10" Name="lvMessages">
                        <ListView.ItemTemplate>
                                <DataTemplate>
                                        <WrapPanel>
                                                <TextBlock Text="Name: " />
                                                <TextBlock Text="{Binding Content}" FontWeight="Bold" />
                                                <TextBlock Text=", " />
                                                <TextBlock Text="Created: " />
                                                <TextBlock Text="{Binding Created}" FontWeight="Bold" />
                                        </WrapPanel>
                                </DataTemplate>
                        </ListView.ItemTemplate>
                </ListView>

And this code behind:

public List<MessageViewModel> Messages {
        get;
        set;
    }

    public MessagePage ()
    {

        InitializeComponent ();

        Messages = new List<MessageViewModel> {
            new MessageViewModel{
                Content="TesztA",
                Created=DateTime.Now
            },
            new MessageViewModel{
                Content="TesztA",
                Created=DateTime.Now.AddMinutes(-1)
            },
            new MessageViewModel{
                Content="TesztA",
                Created=DateTime.Now.AddMinutes(-2)

            }
        };
        this.lvMessages.ItemsSource = Messages;

    }

And when I try to build it, I get an error: 'MyProject.MessagePage' does not contain a definition for 'lvMessages' and no extension method 'lvMessages' accepting a first argument of type 'MyProject.MessagePage' coul d be found (are you missing a using directive or an assembly reference?) In the editor it totally looks cool, the IntelliSense of Xamarin Studio does not show any error.

Upvotes: 0

Views: 529

Answers (1)

Kiss L&#225;szl&#243;
Kiss L&#225;szl&#243;

Reputation: 275

I have found the solution. The ListView must have x:Name, not Name attribute.

Upvotes: 1

Related Questions