我是绑定逻辑的初学者,我正在关注ListView Data Sources。
我根据使用情况调整了教程,但是,WinPhone有一个例外:
When converting a string to DateTime, parse the string to get the date before putting each variable into the DateTime object.
问题是我没有使用任何DateTime对象... Android抛出另一个异常 System.FormatException: One of the identified items was in an invalid format.
我虽然我的变量在我的DataTemplated对象Duration
是它的原因,但我重命名它,它最终不是这个异常的原因......那么发生了什么?
我正在尝试制作以下视图,但是我没有将de map部分放在代码中,因为我只想创建我的列表。
为此,我有以下三个文件:
Page.xaml.cs
public partial class ListeCourses : ContentPage
{
public ListeCourses()
{
InitializeComponent();
initList();
}
ObservableCollection<Course> courses = new ObservableCollection<Course>();
private void initList()
{
ListViewCourses.ItemsSource = courses;
courses.Add(new Course { _Ride = "Caen - Narbonne", _Since = "6 mins", _Duration = "15 mins", _Pseudo = "Simca", _StopNumber = "1" });
courses.Add(new Course { _Ride = "Le Mans - Ruaudin", _Since = "8 mins", _Duration = "8 mins", _Pseudo = "Sixela05", _StopNumber = "2" });
courses.Add(new Course { _Ride = "Rennes - Epitech", _Since = "3 mins", _Duration = "11mins", _Pseudo = "Emixam23", _StopNumber = "1" });
}
}
page.xaml // Each item shown on the image above have another design that just a Label, but it's not the problem at the moment, so I didn't put the final design to focus the main problem.
<ContentPage.Content>
<ListView x:Name="ListViewCourses">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<!--Custom course cell-->
<Grid.RowDefinitions>
<RowDefinition Height="50dp" />
<RowDefinition Height="50dp" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<!-- Top grid -->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70*" />
<ColumnDefinition Width="30*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding _Ride}" Grid.Row="0" Grid.Column="0"/>
<Label Text="{Binding _Since}" Grid.Row="0" Grid.Column="1"/>
</Grid>
<Grid Grid.Row="1">
<!-- Bottom grid -->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="30*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="15*" />
<ColumnDefinition Width="15*" />
</Grid.ColumnDefinitions>
</Grid>
<Label Text="{Binding _Duration}" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding _Pseudo}" Grid.Row="0" Grid.Column="1" />
<Label Text="{Binding _StopNumber}" Grid.Row="0" Grid.Column="2" />
<Button x:Name="More" Text="+" Grid.Row="0" Grid.Column="3"/>
<Button x:Name="Agree" Text="V" Grid.Row="0" Grid.Column="4"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
Course.cs
public class Course
{
public string _Ride { get; set; }
public string _Since { get; set; }
public string _Duration { get; set; }
public string _Pseudo { get; set; }
public string _StopNumber { get; set; }
}
也许这很愚蠢,但是当我在创建这个问题时,在 TAGs部分中,Stackoverflow建议我datetime
TAG ...我真的错过了什么吗?
感谢您的帮助!
调用堆栈 [外部代码]
Project.ni.DLL!Project.Controlers.Driver.ListeCourses.initList()第20行C# Project.ni.DLL!Project.Controlers.Driver.ListeCourses.ListeCourses()第12行C# Project.ni.DLL!Project.App.App()第12行C# Project.WinPhone.ni.EXE!Project.WinPhone.MainPage.MainPage()第18行C# [外部代码] Project.WinPhone.ni.EXE!Project.WinPhone.App.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs e)第96行C#