-1

I use the latest ver of .Net Maui. In the scenario there is ObservableCollection of items bound to ItemsSource's CarouselView. User is supposed to do some actions upon the current item to make it "valid" in order to be able to move to the next one. CarouselView should block user from swiping card to the next one until the current one is valid, and valid state is defined by properties of the item.

First thing that came my mind was to subscribe for one of Scroll or PositionChanged event and cancel the action propagation, but I do not think the events are cancelable, did not find it in the even arguments. Second less desirable way to implement is to add items dynamically to the ObservableCollection of items once current item got valid. It won't be able to go to the next just because the current is always the last. It though seems to be a bit of a hacky way to resolve this, and I would prefer to implement it on a view level rather than model level (adding items on the fly). So if you know more direct ways to get it implemented please let me know. Thanks.

Update: I'd like users to be able to swipe to all previously handled items (all valid), getting back and forward, but only for valid cards.

YMC
  • 4,925
  • 7
  • 53
  • 83

1 Answers1

0

Set the property IsSwipeEnable to false when the current item is not yet valid.

From docs

IsSwipeEnabled, of type bool, which determines whether a swipe gesture will change the displayed item. The default value is true.

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • hmm, good catch, I did not mention it in the question, but I wish though users are able to swipe to all previously handled items (all valid), getting back and forward, but only for valid cards. Other than that would work fine. I think I have to add items dynamically for that – YMC Sep 03 '22 at 01:58
  • Please provide a minimum code sample, but i think also that you will have to add items dynamically – Cfun Sep 03 '22 at 14:59
  • I have seen your question and I think if you can consider using the oncurrentitemchanged event. You may try to change ItemsSource property in the event. – Hongxin Sui-MSFT Sep 05 '22 at 03:07