Xamarin.Forms项目详细信息页面,带有网格,Listview

时间:2019-02-20 09:35:16

标签: xamarin.forms

给出以下“项目详细信息”页面:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.Views.ItemDetailPage"
             Title="{Binding Title}">
    <ScrollView>

    <StackLayout Spacing="2" Padding="15">
        <Label Text="Date:" FontSize="Small"  FontAttributes="Bold"/>
        <Label Text="{Binding Item.Date}" FontSize="Small" />
        <Label Text="School:" FontSize="Small"  FontAttributes="Bold"/>
        <Label Text="{Binding Item.School}" FontSize="Small"/>
        <Label Text="Description:" FontSize="Small"  FontAttributes="Bold" />
        <Label Text="{Binding Item.Description}" FontSize="Small"/>
        <Label Text="Condition:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.Condition}" FontSize="Small"/>
        <Label Text="Offnormal:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.Offnormal}" FontSize="Small"/>
        <Label Text="EventType:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.EventType}" FontSize="Small"/>
        <Label Text="BaseState:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.BaseState}" FontSize="Small"/>
        <Label Text="Code:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.Code}" FontSize="Small"/>
        <Label Text="Account:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.Account}" FontSize="Small"/>
        <Label Text="RestoreFor:" FontSize="Small" FontAttributes="Bold"/>
        <Label Text="{Binding Item.RestoreFor}" FontSize="Small"/>
    </StackLayout>
        </ScrollView>
</ContentPage>

如何在网格或列表视图中显示? 当我尝试将相同的/相似的代码用于将SelectedItem属性发送到此详细信息页面的Listview / Grid时,我得到了除标题之外的空白页面。

任何帮助将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:0)

我知道了。为了清楚起见,我的问题是发送SelectedItem并可以很好地用于Label绑定,但是ListView ItemsSource需要一个List。我对此进行了相应的更改,并且可以进行以下工作:

<ScrollView>
    <!--Spacing="2" Padding="15">-->
    <StackLayout >
        <Label Text="Date:" FontSize="Small"  FontAttributes="Bold"/>
        <Label Text="{Binding Item[0].Date}" FontSize="Small" />

        <ListView x:Name="ItemsListView2"
            ItemsSource="{Binding Item}"
            VerticalOptions="FillAndExpand"
            HasUnevenRows="true"
            IsRefreshing="{Binding IsBusy, Mode=OneWay}"
            CachingStrategy="RecycleElement">

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid BackgroundColor="White" ColumnSpacing="0" RowSpacing="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text ="{Binding Date}" HorizontalOptions="Fill" BackgroundColor="LightBlue" HorizontalTextAlignment="Center" Margin="1"></Label>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ScrollView>

Here's what it looks like