[英]ListView error in Xamarin.Forms
I've got a strange problem with the ListView component. 我在ListView组件上遇到了一个奇怪的问题。 I have his XAML:
我有他的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. 当我尝试构建它时,出现错误:
'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?)
在编辑器中,它看起来非常酷,Xamarin Studio的IntelliSense不会显示任何错误。
I have found the solution. 我找到了解决方案。 The ListView must have x:Name, not Name attribute.
ListView必须具有x:Name,而不是Name属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.