[英]EventHandler Implementation F#
I am implementing the following C#
code in F#
: 我正在F#
实现以下C#
代码:
using Softweb.Xamarin.Controls.iOS;
public class DemoViewController : UIViewController, ICardViewDataSource
{
public CardView DemoCardView { get; set; }
public override void ViewDidLoad()
{
base.ViewDidLoad();
DemoCardView = new CardView();
//Wire up events
DemoCardView.DidSwipeLeft += OnSwipe;
DemoCardView.DidSwipeRight += OnSwipe;
DemoCardView.DidCancelSwipe += OnSwipeCancelled;
DemoCardView.DidStartSwipingCardAtLocation += OnSwipeStarted;
DemoCardView.SwipingCardAtLocation += OnSwiping;
DemoCardView.DidEndSwipingCard += OnSwipeEnded;
}
void OnSwipe(object sender, SwipeEventArgs e)
{
Console.WriteLine("View swiped.\n");
}
void OnSwipeCancelled(object sender, SwipeEventArgs e)
{
Console.WriteLine("Swipe cancelled.\n");
}
void OnSwipeStarted(object sender, SwipingStartedEventArgs e)
{
Console.Write("Started swiping at location {0}\n", e.Location);
}
void OnSwiping(object sender, SwipingEventArgs e)
{
Console.Write("Swiping at location {0}\n", e.Location);
}
void OnSwipeEnded(object sender, SwipingEndedEventArgs e)
{
Console.Write("Ended swiping at location {0}\n", e.Location);
}
}
I am not sure however how to replicate the 我不确定如何复制
DemoCardView.DidSwipeLeft += OnSwipe;
syntax in F#
(what is the equivilant of +=
in F#
). 语法F#
是什么的equivilant +=
在F#
I know this is responsible for event subscription, which makes me think I should use the Add
method in F#
for this, however I'm not sure how. 我知道这是事件订阅的原因,这使我认为我应该为此使用F#
的Add
方法,但是我不确定如何使用。 Also, what are the signatures of the onSwipe
, onSwipeCancelled
... functions should be. 另外, onSwipe
, onSwipeCancelled
...函数的签名应该是什么。 The type expected by DidSwipeLeft
and the others is 'IEvent<EventHandler<SwipeEventArgs>,SwipeEventArgs>
DidSwipeLeft
和其他人期望的类型是'IEvent<EventHandler<SwipeEventArgs>,SwipeEventArgs>
The full API is called XCardView and can be found here: 完整的API称为XCardView,可以在以下位置找到:
https://components.xamarin.com/gettingstarted/XCardView/true https://components.xamarin.com/gettingstarted/XCardView/true
let onSwipe = fun args -> printfn "View swiped"
DemoCardView.DidSwipeLeft.Add(onSwipe)
Or, simply 或者,简单地
DemoCardView.DidSwipeLeft.Add(fun args -> printfn "View swiped")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.