-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CollectionView (and ListView) IsEnabled does not appear to work #19768
Comments
Could be related to this issue. Odd that it never worked, but also I can't recall a situation that I've ever disabled any CollectionView (or ListView, ScrollView) so I get why it may fall through the cracks for so long. |
Instead of disabling the view, you could maybe set the SelectionMode to
|
I don't think changing selection mode is a workaround for me (may be for others). My use case is to have a list on the left and you select an item and then hit edit. Section on the right then lets you edit an objects details while the collection view on the left shows what is currently selected and prevents user selecting something else. The linked Android issue has a workaround from someone to disable the entire pages Content. That did not work for me, so the issue may be slightly different to that one or that disabling the entire page works but only for Android. For my fix I am going to subclass it, add a fake property for FakeIsEnabled and use that to toggle opacity and InputTransparent and never touch IsEnabled. When I get into work I'm going to test it ListView has the same problem or not.
On macOS (screenshots soon) it dims the content so it looks disabled but you can still click another row. That's why my first thought was "odd, I'll make InputTransparent toggle as well so it looks dimmed and also doesn't work" which is when I came across the other bug that it isn't allowing input after setting InputTransparent back again EDIT: Thinking about this more and going to look at iOS UICollectionView there isn't really any |
Updated the code in the repo to show ListView as well as the IsEnabled=true state of both collection types. (Also side note that is interesting but completely unrelated, on macOS the ListViews ItemTemplates DataTemplate does not need a ViewCell, on Windows it will crash unless there is a ViewCell) macOSCollectionView has some sort of enabled state change, ListView does not even though it is using the same cell style (I thought it would as I would have thought Label is getting an IsEnabled state change). WindowsCollectionView works exactly as expected. ListView does the same as macOS. iOS (simulator)Both work the same as macOS (not super surprising considering macOS is MacCatalyst) Android (emulator)CollectionView IsEnabled=false looks disabled but still accepts input. |
If anyone does come across this issue this is my workaround I settled on this, (I'll edit this comment if I find more issues with this and another workaround) public class ModifiedCollectionView : CollectionView
{
// Only need to do this hack for macOS+iOS+Android as this works as expected on Windows.
#if !WINDOWS
protected override void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == IsEnabledProperty.PropertyName)
{
if (IsEnabled)
{
InputTransparent = false;
Opacity = 1.0;
}
else
{
InputTransparent = true;
Opacity = 0.5;
}
}
}
#endif
} although if you want to keep using internal class CollectionViewIsEnabledHackRoutingEffect : RoutingEffect
{
}
#if WINDOWS
internal class CollectionViewIsEnabledHackPlatformEffect : PlatformEffect
{
protected override void OnAttached()
{
}
protected override void OnDetached()
{
}
}
#else
internal class CollectionViewIsEnabledHackPlatformEffect : PlatformEffect
{
protected override void OnAttached()
{
Element.PropertyChanged += CollectionView_PropertyChanged;
}
protected override void OnDetached()
{
Element.PropertyChanged -= CollectionView_PropertyChanged;
}
private void CollectionView_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (sender is CollectionView collectionView)
{
if (e.PropertyName == CollectionView.IsEnabledProperty.PropertyName)
{
if (collectionView.IsEnabled)
{
collectionView.InputTransparent = false;
collectionView.Opacity = 1.0;
}
else
{
collectionView.InputTransparent = true;
collectionView.Opacity = 0.5;
}
}
}
}
}
#endif |
This is still an issue in version 8.0.90 on android with commands and MVVM. When I set IsEnabled="false" on a element in CollectionView, the item`s Opacity and InputTransparent changes as expected. But the command is still triggered if i tap the element. Resulting in "SelectedItems" being mutated. My assumption was that if a element is disabled, nothing would happen if I tap that element. Am I wrong ? |
Description
Settings IsEnabled=false on a CollectionView does not disable it. May be related heavily to #19771
Steps to Reproduce
Link to public reproduction project repository
https://github.com/beeradmoore/maui-issue-CollectionViewIsEnabledTest
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, macOS
Affected platform versions
iOS 17.2.1, Android 13, macOS 14.2.1
Did you find any workaround?
Have not tried yet, but I am going to add a view over the top to prevent interaction (or just try prevent interaction) and drop CollectionView opacity to 50%
Relevant log output
No response
The text was updated successfully, but these errors were encountered: