XAML 为什么使用XAMARIN时列表视图中不显示其他字段

pxiryf3j  于 2022-12-16  发布在  其他
关注(0)|答案(2)|浏览(184)

我正在尝试显示项目,但只显示{Binding Peso}。如果您更改{Binding Peso}并使用{Binding Contenido},您可以看到它显示确定任何帮助请?

<ListView  x:Name="PaqueteList">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Frame BorderColor="Black">
                                    <StackLayout Margin="5" Grid.Column="0"  Orientation="Vertical" 
                                             HorizontalOptions="StartAndExpand" 
                                             VerticalOptions="Center">

                                        <Label  Text ="{Binding Peso}" 
                                           TextColor="Blue"
                                           BackgroundColor="White"                                          
                                        />
                                    
                                        <Label Grid.Column="1" Text ="{Binding TrackingNumber} " 
                                            TextColor="Blue"
                                            BackgroundColor="White"
                                         />
                                        <Label Grid.Column="2" Text ="{Binding Contenido}"
                                          TextColor="Blue"       
                                          BackgroundColor="White"
                                        />
                                    </StackLayout>
                                </Frame>                             
                                
                                
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

我已经将{Binding Peso}更改为{Binding Contenido}等,并且可以正常工作。我只需要显示这样的内容
比索跟踪内容xx年zzzz xx年zzzz xx年zzzz

fzsnzjdm

fzsnzjdm1#

在您的ViewCell上试试这个:

<ViewCell>
    <Frame BorderColor="Black">
        <Grid
            Margin="5"
            HorizontalOptions="StartAndExpand"
            VerticalOptions="Center"
            ColumnDefinitions="*, *, *">
            <Label
                BackgroundColor="White"
                Text="{Binding Peso}"
                TextColor="Blue" />
            <Label
                Grid.Column="1"
                BackgroundColor="White"
                Text="{Binding TrackingNumber}"
                TextColor="Blue" />
            <Label
                Grid.Column="2"
                BackgroundColor="White"
                Text="{Binding Contenido}"
                TextColor="Blue" />
        </Grid>
    </Frame>
</ViewCell>
aiazj4mn

aiazj4mn2#

您应该将子视图添加到ListView中,如下所示:

<ListView>
  <ViewCell>
      <StackLayout>
         <Frame>
             <Grid>
             </Grid>
         <Frame/>
      </StackLayout>
   </ViewCell>
</ListView>

下面是代码片段,供您参考:

<ListView  x:Name="PaqueteList" > 
                <ListView.ItemTemplate>
                    <DataTemplate>
                
                     <ViewCell>

                        <StackLayout Margin="5" Orientation="Vertical" HorizontalOptions="StartAndExpand" VerticalOptions="Center">
                            <Frame BorderColor="Black">
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                        
                                        <Label  Grid.Column="0" Text ="{Binding Peso}"
                                           TextColor="Blue"
                                           BackgroundColor="White"/>

                                        <Label Grid.Column="1" Text ="{Binding TrackingNumber} "
                                            TextColor="Blue"
                                            BackgroundColor="White"
                                         />

                                        <Label Grid.Column="2" Text ="{Binding Contenido}"
                                          TextColor="Blue"      
                                          BackgroundColor="White" />

                           
                        </Grid>
                            </Frame>
                        </StackLayout>

                    </ViewCell>
                 
                </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

相关问题