【问题标题】:How to achieve Pagination in Xamarin forms如何在 Xamarin 表单中实现分页
【发布时间】:2021-12-26 13:42:06
【问题描述】:

我需要在列表视图页面中实现分页。在这里,我在一个表中显示成百上千条记录,因此需要分页功能。

由于记录的数量,无限向下滚动方法不可行。与附图相同。

【问题讨论】:

标签: c# xamarin xamarin.forms


【解决方案1】:
<ScrollView>
<SomeDataContentView Data={Binding SelectedData} />
</ScrollView>


<StackLayout BindableLayout.ItemSource={Binding ListOfPageNumber}
x:Name="SomeStack"
Orientation="Horizontal">
   <BindableLayout.ItemTemplate>
<DataTemplate>
<Button Text={Binding .}
Command={Binding Path=BindingContext.SelectPage_Command, Source={x:Reference SomeStack}
CommandParameter={Binding .}
</DataTemplate>
</BindableLayout.ItemTemplate>

视图模型:

public SelectPage_Command = new Command((param) =>
{
   var pageNo = (int)param;

SelectedData = DataDividedByPage[pageNo];
});

SomeDataContentView.cs:

SomeDataContentView : ContentView

        public static readonly BindableProperty DataProperty = BindableProperty.Create(
nameof(Data), typeof(string), typeof(SomeDataContentView ), defaultValue: "", propertyChanged: DoSomethingWhenDataChanged);
        public string Data
        {
            get => (string)GetValue(DataProperty perty);
            set => SetValue(DataProperty , value);
        }

并创建您的 SomeDataContentView.xaml 以显示您想要的数据。

这可能是我的做法。

我是凭记忆完成的,跳过了一两件事。但如果你需要我,我稍后会回来。

【讨论】:

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