【问题标题】:Xamarin - Binding to call a functionXamarin - 绑定调用函数
【发布时间】:2018-06-16 02:21:29
【问题描述】:

我正在使用一个名为 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";
    }
}
}

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

【问题讨论】:

  • 您的 XAML 中的命名空间是 TheOctant.MainPage,但您的 MainPagePullToRefreshTest 的命名空间中,也许这就是问题所在?
  • @RonBeyer 哈哈我把它改成了 PullToRefreshTest 因为我不想让任何人看到它哈哈。 oops e_e 但其实是同一个命名空间

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


【解决方案1】:

没有。顾名思义,RefreshCommand 需要是Command

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

【讨论】:

  • 哦,好吧。所以我只需将它添加到我的 MainPage.Xaml.cs 中就可以了?
  • 它可以工作,但现在我得到了一个可以永远运行的微调器。有什么想法吗?
  • 阅读文档:github.com/jamesmontemagno/… - 您需要手动绑定或设置 IsRefreshing 属性
  • 是的,我有,但我不确定如何设置令人耳目一新的东西
猜你喜欢
  • 2014-10-21
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
相关资源
最近更新 更多