如何在Xamarin.Forms中使用PKPaymentButton
我在Xamarin.Forms中有一个页面,在该页面中,我必须使用与PassKit中UIButton的子类相同的PKPaymentButton类来显示PKPaymentButton。 我已经编写了一个自定义按钮说明程序,并试图将该按钮转换为PKPayment按钮。 到目前为止,在自定义渲染器中,我们可以更改按钮的外观,但我们可以在我的示例PKPaymentButton中使用类似创建新按钮实例的方法,并将其替换为button 更新- 我通过以下方式实现了这一目标:-如何在Xamarin.Forms中使用PKPaymentButton,xamarin.forms,Xamarin.forms,我在Xamarin.Forms中有一个页面,在该页面中,我必须使用与PassKit中UIButton的子类相同的PKPaymentButton类来显示PKPaymentButton。 我已经编写了一个自定义按钮说明程序,并试图将该按钮转换为PKPayment按钮。 到目前为止,在自定义渲染器中,我们可以更改按钮的外观,但我们可以在我的示例PKPaymentButton中使用类似创建新按钮实例的方法,并将其替换为button 更新- 我通过以下方式实现了这一目标:- public class Ap
public class ApplePayButtonRenderer : Xamarin.Forms.Platform.iOS.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var button = new PKPaymentButton(PKPaymentButtonType.Buy, PKPaymentButtonStyle.Black);
SetNativeControl(button);
}
}
}
公共类ApplePayButtonRenderer:Xamarin.Forms.Platform.iOS.ButtonRenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(e.OldElement==null)
{
var button=新的PKPaymentButton(PKPaymentButtonType.Buy,PKPaymentButtonStyle.Black);
SetNativeControl(按钮);
}
}
}
现在我正在尝试点击Xamarin。表单您可以使用消息中心在单击付款按钮时发送消息 在自定义渲染器中
private void按钮\u TouchUpInside(对象发送方,事件参数e)
{
MessagingCenter.Send(这是“PayButtonClick”);
}
以形式
将以下代码添加到包含付款按钮的ContentPage的构造函数中
public xxxPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object>(this, "PayButtonClick",(args)=> {
//do some thing you want
});
}
public xxxPage()
{
初始化组件();
MessagingCenter.Subscribe(此“PayButtonClick”(参数)=>{
//做你想做的事
});
}
您想让我给您举一个如何将您的事件带回XF的示例吗?在这里使用委托事件组合是否有意义?
private void Button_TouchUpInside(object sender, EventArgs e)
{
MessagingCenter.Send<Object>(this,"PayButtonClick");
}
public xxxPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object>(this, "PayButtonClick",(args)=> {
//do some thing you want
});
}