【问题标题】:Xamarin.Forms Item Detail page with Grid, Listview带有网格、列表视图的 Xamarin.Forms 项目详细信息页面
【发布时间】:2019-02-21 04:54:35
【问题描述】:

鉴于以下项目详细信息页面:

<?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 使用相同/相似的代码时,我得到一个除标题之外的空白页面。

任何帮助将不胜感激。

谢谢

【问题讨论】:

  • Item 是您的列表视图模型,对吗?如果正确,则从绑定对象中删除“项目”。你可以这样实现
  • 用预期的设计更新您的问题以显示数据
  • “当我尝试过时” - 然后向我们展示您尝试过的内容,以便我们帮助您解决问题

标签: xamarin.forms


【解决方案1】:

我想通了。需要明确的是,我的问题是发送 SelectedItem 并且对于标签绑定工作正常,但 ListView ItemsSource 需要一个列表。我相应地改变了它并且以下工作:

<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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多