diff --git a/README.md b/README.md index f865ef6..c978694 100644 --- a/README.md +++ b/README.md @@ -1 +1,86 @@ **[View document in Syncfusion Xamarin Knowledge base](https://www.syncfusion.com/kb/12267/how-to-conditionally-handle-the-swiping-using-mvvm-in-xamarin-forms-listview-sflistview)** + +## Sample + +```xaml + + + + + . . . + . . . + + + + + + + + + + + + + + + + + + + +ViewModel.cs: + +public Command SwipeStartedCommand { get; set; } + +SwipeStartedCommand = new Command(OnSwipeStarted); + +private void OnSwipeStarted(object obj) +{ + var args = obj as Syncfusion.ListView.XForms.SwipeStartedEventArgs; + if ((args.ItemData as Contacts).BackgroundColor == Color.LightGray) + { + args.Cancel = true; + } +} + +C#: + +void OnEvent (object sender, object eventArgs) +{ + if (Command == null) { + return; + } + + object resolvedParameter; + if (CommandParameter != null) { + resolvedParameter = CommandParameter; + } else if (Converter != null) { + resolvedParameter = Converter.Convert (eventArgs, typeof(object), AssociatedObject, null); + } else { + resolvedParameter = eventArgs; + } + + if (Command.CanExecute (resolvedParameter)) { + Command.Execute (resolvedParameter); + } +} + +static void OnEventNameChanged (BindableObject bindable, object oldValue, object newValue) +{ + var behavior = (EventToCommandBehavior)bindable; + if (behavior.AssociatedObject == null) { + return; + } + + string oldEventName = (string)oldValue; + string newEventName = (string)newValue; + + behavior.DeregisterEvent (oldEventName); + behavior.RegisterEvent (newEventName); +} +```