Xamarin - 绑定调用函数

时间:2018-06-16 02:21:30

标签: c# xamarin binding pull-to-refresh

我正在使用名为Refractored.XamForms.PullToRefresh的nuget包。

所以我的MainPage.Xaml有:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:TheOctant"
         xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"
         x:Class="TheOctant.MainPage">

<StackLayout>
    <ScrollView>
        <controls:PullToRefreshLayout x:Name="ptrl" RefreshCommand="{Binding UponRefresh}" RefreshColor="Blue">
            <local:ZoomWebView x:Name="webview" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></local:ZoomWebView>
        </controls:PullToRefreshLayout>
    </ScrollView>
</StackLayout>
</ContentPage>

请查看RefreshCommand="{Binding UponRefresh}",我正在尝试将其绑定到MainPage.Xaml.cs

中的c#函数

所以这是我在MainPage.Xaml.cs中失败的尝试:

namespace TheOctant
{
public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();
    }

    public void UponRefresh()
    {
        webview.Source = "http://www.google.com";
    }
}
}

但它不起作用。我这样做了吗?

1 个答案:

答案 0 :(得分:0)

没有。顾名思义,RefreshCommand必须是Command

public ICommand UponRefresh
{
    get {
        return new Command(async () =>
        {
            webview.Source = "http://www.google.com";
        });
    }
}