Proposal: add a CanSwipe bool property to the SwipeControl type
See original GitHub issueProposal: Add a CanSwipe bool property to the SwipeControl type
Summary
I’d like to have a bool CanSwipe { get; set; }
property to the SwipeControl
so that swipe can be turned off and on easily.
Rationale
When using the SwipeControl
in a ListView
there could be situations were swipe actions are disabled for particular read-only items.
Today this is possible by having an ItemTemplateSelector
that switches between 2 datatemplates: one with the SwipeControl
, one without.
Having a bool CanSwipe { get; set; }
property to the SwipeControl
would make this super easy.
Functional Requirements
- The
CanSwipe
property should support databinding (e.g. be a dependency property) - The
CanSwipe
property should have a default value oftrue
- When the property changes, the swipe capability must be updated accordingly
Important Notes
I did some prototyping and I think the implementation shouldn’t too hard. Here is what I did:
- add a new bool dependency property
- update the
InitializeInteractionTracker
method to setup the interaction tracker according to the value of theCanSwipe
property
if (CanSwipe())
{
m_visualInteractionSource.get().ManipulationRedirectionMode(winrt::VisualInteractionSourceRedirectionMode::CapableTouchpadOnly);
m_visualInteractionSource.get().PositionXSourceMode(m_isHorizontal ? winrt::InteractionSourceMode::EnabledWithInertia : winrt::InteractionSourceMode::Disabled);
m_visualInteractionSource.get().PositionYSourceMode(!m_isHorizontal ? winrt::InteractionSourceMode::EnabledWithInertia : winrt::InteractionSourceMode::Disabled);
}
else
{
m_visualInteractionSource.get().ManipulationRedirectionMode(winrt::VisualInteractionSourceRedirectionMode::Off);
m_visualInteractionSource.get().PositionXSourceMode(winrt::InteractionSourceMode::Disabled);
m_visualInteractionSource.get().PositionYSourceMode(winrt::InteractionSourceMode::Disabled);
}
When the DP changes, if the m_visualInteractionSource
is defined, update the interaction mode as well.
Open Questions
None at the moment.
- Maybe we would like to disable only swipe left and/or swipe right. In that case we might want to have 2 properties
CanSwipeLeft
andCanSwipeRight
or having a newMode
=None
instead ofReveal
andExecute
.
Misc
This has been discussed offline with @kikisaints. I’m happy to submit a PR if that’s easier to discuss.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (5 by maintainers)
I’d say, if the dev sets CanSwipe to false, he doesn’t want the user to be able to access those swipe commands. So if the user has already opened the control, it should immediately close when CanSwipe is switched to false. At least for me, that would be the logical behavior.
It would also seem like a glitch if the control stays open, can be closed, and then cannot be opened again. Also if it stays open not interactable, it would seem broken, caught in some intermediary state.
To add to this, I would expect that this would be possible to enable / disable individual
SwipeItem
s using theCanExecute
property of the already existingSwipeControl.Command
--> by indicating that the command cannot execute, you disable theSwipeItem