【问题标题】:Paged Datagrid using Syncfusion in Xamarin.Forms在 Xamarin.Forms 中使用 Syncfusion 的分页数据网格
【发布时间】:2018-12-11 12:58:20
【问题描述】:

我正在尝试使用 MVVM 架构和 Syncfusion 控件显示分页网格。我设法在 UWP 中使用 SfDataGrid 做到了这一点,但我似乎无法在 Xamarin.Forms 中正确使用它。

如果我不使用寻呼机,线条会出现在网格中。 (请看下面的代码)

    <xForms:SfDataGrid
     x:Name="datagrid"
     AutoGenerateColumns="False"
     ItemsSource="{Binding Lines}"
     ColumnSizer="Star"
     DefaultColumnWidth="200"
     Columns="{Binding GridColumns, Mode=TwoWay}" />

但是当我尝试像这样使用寻呼机时:

        <xForms:SfDataGrid
            x:Name="datagrid"
            AutoGenerateColumns="False"
            ItemsSource="{Binding PagedSource, Source={x:Reference Name=dataPager}}"
            ColumnSizer="Star"
            DefaultColumnWidth="200"
            Columns="{Binding GridColumns, Mode=TwoWay}" />

        <dataPager:SfDataPager
            Source="{Binding Lines, Mode=TwoWay}"
            x:Name="dataPager"
            Margin="5" Grid.Row="1" PageSize="7"
            HorizontalOptions="FillAndExpand" />

我得到以下结果:Grid 是空的,没有抛出异常,我在输出中找不到任何绑定错误。

另外,我认为官方 Syncfusion 文档中的分页示例可能不完整,因为它声明必须在 Grid 的 ItemsSource 和 Pager 的 Source 之间进行绑定,但这并没有出现在 xaml 代码中那里展示的样本。

https://help.syncfusion.com/xamarin/sfdatagrid/paging?cs-save-lang=1&cs-lang=csharp

这是我遗漏的东西还是我需要使用后面的代码才能使其工作?

【问题讨论】:

  • 您是否为表单编译了同步融合示例解决方案?
  • @NickKovalsky 我不知道您指的是哪种解决方案。能否请您提供更多详细信息?
  • 安装 sdk 并打开/构建 SampleBrowser.SfDataGrid.sln 后安装 xamarin 示例
  • @NickKovalsky 感谢您的建议,但该示例包含一个未分页的 SfDataGrid 示例。我已经设法绑定网格线,分页似乎是问题(我也用一些类似的代码为 UWP 解决了这个问题,似乎无法以表格形式得到它)

标签: xamarin.forms uwp paging syncfusion


【解决方案1】:

感谢您使用 Syncfusion 产品。

我们检查了您的查询和共享的代码,您需要设置绑定源,同时将值设置为“SfDataGrid.Columns”属性。请在下面找到相同的代码 sn-p。

<ContentPage.BindingContext> 
    <local:ViewModel x:Name="viewModel" /> 
</ContentPage.BindingContext> 
<ContentPage.Content> 
    <Grid> 
        <Grid.RowDefinitions> 
            <RowDefinition Height="*" /> 
            <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
        <sfgrid:SfDataGrid x:Name="sfGrid"  
                           Grid.Row="0" 
                           AutoGenerateColumns="False" 
                           ColumnSizer="Star" 
                           DefaultColumnWidth="200" 
                           ItemsSource="{Binding PagedSource, Source={x:ReferencedataPager}}" 
                           Columns="{Binding GridColumns, Source={x:ReferenceviewModel}}" 
                           /> 
        <sfpager:SfDataPager x:Name ="dataPager" 
                             Margin="5" 
                             HorizontalOptions="FillAndExpand" 
                             Grid.Row="1" 
                             PageSize="7" 
                             HeightRequest ="50" 
                             Source="{Binding OrdersInfo}" 
                     /> 
    </Grid> 
</ContentPage.Content> 

我们已经准备了样品以满足您的要求,您可以从以下链接下载相同的样品。 示例链接:http://www.syncfusion.com/downloads/support/directtrac/221044/ze/DataGridDemo-741889615

关于您对XAML代码文档的查询“必须在Grid的ItemsSource和Pager的Source之间进行绑定”,我们将更新文档的XAML代码。

问候, Vigneshkumar R

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2014-10-07
    相关资源
    最近更新 更多