Windows 上的 RefreshView 拉取方向

Download Sample下载示例

此特定于通用 Windows 平台的平台特定功能使 RefreshView 的拉动方向可以更改,以匹配正在显示数据的可滚动控件的方向。 其使用方式是在 XAML 中将 RefreshView.RefreshPullDirection 可绑定属性设置为 RefreshPullDirection 枚举的值:

<ContentPage ...
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core">
    <RefreshView windows:RefreshView.RefreshPullDirection="LeftToRight"
                 IsRefreshing="{Binding IsRefreshing}"
                 Command="{Binding RefreshCommand}">
        <ScrollView>
            ...
        </ScrollView>
    </RefreshView>
 </ContentPage>

或者,可以使用 Fluent API 从 C# 使用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
...
refreshView.On<Windows>().SetRefreshPullDirection(RefreshPullDirection.LeftToRight);

RefreshView.On<Windows> 方法指定此特定于平台的功能仅在通用 Windows 平台上运行。 Xamarin.Forms.PlatformConfiguration.WindowsSpecific 命名空间中的 RefreshView.SetRefreshPullDirection 方法用于设置 RefreshView 的拉取方向,RefreshPullDirection 枚举提供四个可能的值:

  • LeftToRight 指示从左到右的拉取会启动刷新。
  • TopToBottom 指示从上到下拉的拉取会启动刷新,并且是 RefreshView 的默认拉取方向。
  • RightToLeft 指示从右到左的拉取会启动刷新。
  • BottomToTop 指示从下到上的拉取会启动刷新。

此外,GetRefreshPullDirection 方法还可用于返回 RefreshView 的当前 RefreshPullDirection

结果是指定的 RefreshPullDirection 应用于 RefreshView,以设置拉取方向来匹配显示数据的可滚动控件的方向。 以下屏幕截图显示了具有 LeftToRight 拉取方向的 RefreshView

Screenshot of a RefreshView with a left to right pull direction, on UWP

注意

更改拉取方向时,进度圈的起始位置会自动旋转,以便箭头开始的位置与拉取方向的相应位置对应。