简体   繁体   中英

How can I bind to an event with a custom control in MugenMvvm with Xamarin iOS

I want to bind a TouchUpInside event to a custom control on Xamarin iOS with MugenMvvm.

bindingSet.Bind(moreThanFourHoursButton).To(() => (vm, ctx) => vm.TimeButtonClickedCommand)

I tried the above code but I get following Exception:

Error: The binding member cannot be obtained from the path 'DefaultBindingMember' on the 'Mobile.EDevice.iOS.Views.Custom.TimeButton'. at MugenMvvmToolkit.Binding.Infrastructure.BindingMemberProvider.GetBindingMember (System.Type sourceType, System.String path, System.Boolean ignoreAttachedMembers, System.Boolean throwOnError) [0x0010a] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.BindingExtensions.TryGetBindingMemberValue[TSource,TValue] (TSource source, MugenMvvmToolkit.Binding.Models.BindingMemberDescriptor 2[TSource,TValue] member, System.Object[] args, System.Boolean throwOnError, TValue& value) [0x0003f] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.BindingExtensions.GetBindingMemberValue[TSource,TValue] (TSource source, MugenMvvmToolkit.Binding.Models.BindingMemberDescriptor 2[TSource,TValue] member, System.Object[] args) [0x00000] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.BindingExtensions.GetBindingMemberValue[TSource,TValue] (TSource source, MugenMvvmToolkit.Binding.Models.BindingMemberDescriptor 2[TSource,TValue] member) [0x00007] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.BindingBuilderExtensions.Bind[TTarget,TSource] (MugenMvvmToolkit.Binding.Interfaces.IBindingBuilder builder, TTarget targetGeneric) [0x00000] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.Builders.BindingSet 2[TSource,TValue] member) [0x00007] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.BindingBuilderExtensions.Bind[TTarget,TSource] (MugenMvvmToolkit.Binding.Interfaces.IBindingBuilder builder, TTarget targetGeneric) [0x00000] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at MugenMvvmToolkit.Binding.Builders.BindingSet 1[TSource].Bind[TLocalTarget] (TLocalTarget target) [0x00006] in <89993fb2052d4882bce9f7d6fb2304e4>:0 at Mobile.EDevice.iOS.Views.Controllers.ActivityTracking.ActivityDurationViewController.ViewDidLoad () [0x00a1b] in /Users/Admin/Documents/CimziaCompanionApp-Mobile/src/iOS/Views/Controllers/ActivityTracking/ActivityDurationViewController.cs:154 at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_bool_IntPtr (intptr,intptr,intptr,bool,intptr) at UIKit.UIViewController.PresentViewController (UIKit.UIViewController viewControllerToPresent, System.Boolean animated, System.Action completionHandler) [0x0006e] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/ src/build/ios/native/UIKit/UIViewController.g.cs:789 at MugenMvvmToolkit.iOS.Infrastructure.Mediators.ModalViewMediator.ShowView (MugenMvvmToolkit.iOS.Interfaces.Views.IModalView view, System.Boolean isDialog, MugenMvvmToolkit.Interfaces.Models.IDataContext context) [0x0005f] in <5ec134adfe6542a4bd7f31656741c9a6>:0 at MugenMvvmToolkit.Infrastructure.Mediators.WindowViewMediatorBase 1+<>c[TView].<ShowInternal>b__55_2 (MugenMvvmToolkit.Infrastructure.Mediators.WindowViewMediatorBase 1[TView] base, System.Boolean b, MugenMvvmToolkit.Interfaces.Models.IDataContext arg3) [0x00007]

好吧,所以我想出来了,这是我将我的Command绑定到自定义EventHandler的方式:

bindingSet.Bind(moreThanFourHoursButton, nameof(moreThanFourHoursButton.Click)).To(() => (vm, ctx) => vm.TimeButtonClickedCommand)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM