在Xamarin.Forms中构建一个可以在iOS和Android上运行的列表视图

时间:2016-11-17 10:07:10

标签: xamarin xamarin.forms

I want to create this view in Xamarin.Forms

public class HelpModel : BaseStateModel
{
    ObservableCollection<HelpCellViewModel> Help { get; set; }
}

public class HelpViewModel : BaseStateViewModel<HelpModel>
{

    List<HelpCellViewModel> _cellViewModels = new List<HelpCellViewModel>();

    public HelpViewModel()
    {
        this.Title = R.String.main_tabname_help;

        _cellViewModels.Add(new HelpCellViewModel()
        {

        });
    }

}

1 个答案:

答案 0 :(得分:1)

在xaml中,您可以按照

声明List
<ListView x:Name="listView"
            IsVisible="true"
            ItemsSource="{x:Static local:App.BorrowedBooks}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand">
                                <Label Text="{Binding Name}" HorizontalOptions="Center"/>
                                <Label Text="{Binding Author}" Font="10" HorizontalOptions="Center"/>
                            </StackLayout>
                        </ViewCell.View>
                     </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
     </ListView>

可以在xaml.cs文件中访问它,如下所示

public BookList ()
        {

            InitializeComponent ();
            listView.ItemSelected += (sender, e) => {
                 var selectedBook = (Book)e.SelectedItem;
                 var bookDetailsPage = new BookDetails (selectedBook);

                 };
        }