【问题标题】:how i can set two listview in one page in xamarin我如何在 xamarin 的一页中设置两个列表视图
【发布时间】:2020-02-04 20:12:55
【问题描述】:

我在一页上有两个列表视图,但问题是刷新列表视图时只刷新一个列表,滚动列表视图时也滚动一个列表视图,

有关更多信息,我无法将两个列表视图合并为一个,因为我在某些情况下与附件列表视图有关

xaml 代码

        <StackLayout>
            <ListView x:Name="detailsList" HeightRequest="5000" ItemsSource="{Binding DetailsList}" 
                  IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshCommand}">

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal" Padding="5">
                                <StackLayout HorizontalOptions="FillAndExpand">
                                    <es:Label Text="{Binding Value}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand" />
                                    <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                </StackLayout>
                                <StackLayout Padding="0,0,0,2">
                                    <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="{Binding Color}" 
                                          HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

            <ListView x:Name="Attachments" ItemsSource="{Binding Attachments}" SeparatorVisibility="None" BackgroundColor="White" HasUnevenRows="true" SelectionMode="None"
                                IsPullToRefreshEnabled="false" RefreshCommand="{Binding RefreshCommand}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell Tapped="Attachment_Tapped">
                            <StackLayout Orientation="Horizontal" Padding="5">
                                <StackLayout HorizontalOptions="FillAndExpand">
                                    <es:Label Text="{Binding Value.AttachmentTitle}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand"/>
                                    <Image Source="attach.png"  HorizontalOptions="EndAndExpand"></Image>
                                    <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                </StackLayout>
                                <StackLayout Padding="0,0,0,2">
                                    <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="{Binding Color}" 
                                               HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        </StackLayout>

我尝试执行此代码但仍然无法正常工作,我尝试执行ListView.FooterTemplate 但无济于事

          <StackLayout>
                <ListView x:Name="detailsList" HeightRequest="5000" ItemsSource="{Binding DetailsList}" 
                      IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshCommand}">

                    <ListView.HeaderTemplate>
                        <DataTemplate>
                            <ListView x:Name="Attachments" ItemsSource="{Binding Attachments}" 
                                    IsPullToRefreshEnabled="false" RefreshCommand="{Binding RefreshCommand}">
                                <ListView.ItemTemplate>
                                    <DataTemplate>
                                        <ViewCell Tapped="Attachment_Tapped">
                                            <StackLayout Orientation="Horizontal" Padding="5">
                                                <StackLayout HorizontalOptions="FillAndExpand">
                                                    <es:Label Text="{Binding Value.AttachmentTitle}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand"/>
                                                    <Image Source="attach.png"  HorizontalOptions="EndAndExpand"></Image>
                                                    <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                                </StackLayout>
                                                <StackLayout Padding="0,0,0,2">
                                                    <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="{Binding Color}" 
                                                   HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                                </StackLayout>
                                            </StackLayout>
                                        </ViewCell>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </DataTemplate>
                    </ListView.HeaderTemplate>

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal" Padding="5">
                                    <StackLayout HorizontalOptions="FillAndExpand">
                                        <es:Label Text="{Binding Value}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand" />
                                        <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                    </StackLayout>
                                    <StackLayout Padding="0,0,0,2">
                                        <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="{Binding Color}" 
                                              HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                    </StackLayout>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>

谢谢你提前:)

【问题讨论】:

  • 为什么同一个页面有两个不同的列表?

标签: xamarin xamarin.android xamarin.ios


【解决方案1】:

我已将&lt;ListView.HeaderTemplate&gt; 替换为&lt;/ListView.Footer&gt;

此 XAML 代码运行良好

                    <ListView.Footer>
                        <ListView x:Name="Attachments" ItemsSource="{Binding Attachments}" SeparatorVisibility="None" BackgroundColor="White" HasUnevenRows="true" SelectionMode="None"
                                    IsPullToRefreshEnabled="false" RefreshCommand="{Binding RefreshCommand}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell Tapped="Attachment_Tapped">
                                        <StackLayout Orientation="Horizontal" Padding="5">
                                            <StackLayout HorizontalOptions="FillAndExpand">
                                                <!--<es:Label Text="{Binding Value.AttachmentTitle}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand"/>-->
                                                <Image Source="attach.png"  HorizontalOptions="EndAndExpand"></Image>
                                                <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                            </StackLayout>
                                            <StackLayout Padding="0,0,0,2">
                                                <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="#795C8E" 
                                                   HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                            </StackLayout>
                                        </StackLayout>
                                    </ViewCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </ListView.Footer>

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal" Padding="5">
                                    <StackLayout HorizontalOptions="FillAndExpand">
                                        <es:Label Text="{Binding Value}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand" />
                                        <BoxView BackgroundColor="#eeeeee" HeightRequest="2" />
                                    </StackLayout>
                                    <StackLayout Padding="0,0,0,2">
                                        <es:Label Text="{Binding Key}" WidthRequest="100" MinimumWidthRequest="100" TextColor="{Binding Color}" 
                                              HorizontalTextAlignment="Start" VerticalTextAlignment="Center" />
                                    </StackLayout>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    相关资源
    最近更新 更多