列表不显示项目
list not displaying items
我在列表视图中显示项目时遇到问题。我尝试添加 Mode= twoway、oneway 或 default。
我检查了绑定
<ListView x:Name="list"
HasUnevenRows="True"
IsPullToRefreshEnabled="True"
HorizontalOptions="CenterAndExpand"
VerticalOptions="FillAndExpand"
VerticalScrollBarVisibility="Never"
CachingStrategy="RecycleElement"
ItemsSource="{Binding DateFormatList}"
SeparatorVisibility="Default" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding DateType}" TextColor="black" HorizontalOptions="Start" FontSize="14" HorizontalTextAlignment="Center" ></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的页面背面
public DateSettings()
{
InitializeComponent();
BindingContext = new CustomSettingsViewModel();
}
我在视图模型中的 Ctor
public List<DateFormat> DateFormatList { get; private set; }
public CustomSettingsViewModel()
{
DateFormatList = new List<DateFormat>();
DateFormatList.Add(new DateFormat
{
DateType = "yy/dd/mm",
});
}
型号
public class DateFormat
{
public string DateType;
}
您只能绑定到 public 个属性
public class DateFormat
{
public string DateType { get; set; }
}
我在列表视图中显示项目时遇到问题。我尝试添加 Mode= twoway、oneway 或 default。
我检查了绑定
<ListView x:Name="list"
HasUnevenRows="True"
IsPullToRefreshEnabled="True"
HorizontalOptions="CenterAndExpand"
VerticalOptions="FillAndExpand"
VerticalScrollBarVisibility="Never"
CachingStrategy="RecycleElement"
ItemsSource="{Binding DateFormatList}"
SeparatorVisibility="Default" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding DateType}" TextColor="black" HorizontalOptions="Start" FontSize="14" HorizontalTextAlignment="Center" ></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的页面背面
public DateSettings()
{
InitializeComponent();
BindingContext = new CustomSettingsViewModel();
}
我在视图模型中的 Ctor
public List<DateFormat> DateFormatList { get; private set; }
public CustomSettingsViewModel()
{
DateFormatList = new List<DateFormat>();
DateFormatList.Add(new DateFormat
{
DateType = "yy/dd/mm",
});
}
型号
public class DateFormat
{
public string DateType;
}
您只能绑定到 public 个属性
public class DateFormat
{
public string DateType { get; set; }
}