你好,我正在处理Xamarin.Forms中的问题。在ListView
中出现了数据绑定问题。在模型中有一个字符串值和一个列表,该列表是ListView
的ItemsSource
,而字符串值应该显示在每个单元格行中。
XMAL视图
<ListView ItemsSource="{Binding StudentList, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text={Binding Name} />
<Label Text={Binding ConstantName} /> //// Not present in Itemsource. Should bind from Model. It does not render.
</Stacklayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C#
public ObservableCollection<PagingButtons> _lstPagingButtons { get; set; }
public ObservableCollection<PagingButtons> lstPagingButtons
{
get { return _lstPagingButtons; }
set
{
_lstPagingButtons = value;
OnPropertyChanged();
}
}
string _ConstantName {get; set;} = "Xamarin";
public string ConstantName
{
get { return _ConstantName; }
set { __ConstantName = value; OnPropertyChange();
}
我知道我可以把ConstantName
添加到PagingButtons
类中,但是我有30-40个类都有这种情况,这样做会很繁琐,也不是有效的方法。
_ConstantName
是私有字段,因此此处呈现的代码将无法正常工作。另外,我不知道root
关键字,但这可能是我的知识缺失。 - Gerald Versluis