maui icon indicating copy to clipboard operation
maui copied to clipboard

CollectionView selecteditem background lost if collectionview (or parent) IsEnabled changed.

Open Toomas75 opened this issue 1 year ago • 5 comments

Description

CollectionView selecteditem background lost if collectionview (or parent) IsEnabled changed. And buttons "ripple" effect still missing.

Steps to Reproduce

Run attached project -> click buttons. MauiBug.zip

Link to public reproduction project repository

No response

Version with bug

Nightly / CI build (Please specify exact version)

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI, Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Toomas75 avatar Feb 15 '24 15:02 Toomas75

Microsoft.Maui.Controls and Microsoft.Maui.Controls.Compatibility 8.0.10-nightly.10055

Toomas75 avatar Feb 15 '24 15:02 Toomas75

` <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MauiBug.CollectionViewCurrentRow" Title="CollectionViewCurrentRow"> <ContentPage.Resources>

    <ResourceDictionary>

        <Style TargetType="Grid">
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="LightGreen" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ResourceDictionary>
</ContentPage.Resources>

<Grid x:Name="ParentGrid" RowDefinitions="Auto, *">
    <VerticalStackLayout Padding="10" Spacing="10">
        <Button Text="List.IsEnabled - selecteditem backround lost" Command="{Binding IsEnabledTriggerCmd}"></Button>
        <Button Text="List.IsEnabled - selecteditem backround lost" Command="{Binding ParentGridIsEnabledTriggerCmd}"></Button>

    </VerticalStackLayout>
    <CollectionView x:Name="List" Grid.Row="1" SelectionMode="Single" VerticalOptions="Start" SelectedItem="{Binding SelectedItemValue}" ItemsSource="{Binding Values}"  >
        
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Label Text="{Binding}" FontSize="Large"/>
                </Grid>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView> 
</Grid>

</ContentPage>`

Toomas75 avatar Feb 15 '24 17:02 Toomas75

`public partial class CollectionViewCurrentRow : ContentPage { public ICommand IsEnabledTriggerCmd { get; set; } public ICommand ParentGridIsEnabledTriggerCmd { get; set; } public object SelectedItemValue { get; set; } public ArrayList Values { get; set; } public CollectionViewCurrentRow() { //https://github.com/dotnet/maui/issues/20615 InitializeComponent();

	IsEnabledTriggerCmd = new Command(IsEnabledTriggerCmd_Executed);
	ParentGridIsEnabledTriggerCmd = new Command(ParentGridIsEnabledTriggerCmd_Executed);

	Values = ["First", "Second", "Third"];
	SelectedItemValue =Values[0]!;
	BindingContext = this;
}
private void IsEnabledTriggerCmd_Executed()
{
	List.IsEnabled = false;
	List.IsEnabled = true;
}
private void ParentGridIsEnabledTriggerCmd_Executed()
{
	ParentGrid.IsEnabled = false;
    ParentGrid.IsEnabled = true;
}

}`

Toomas75 avatar Feb 15 '24 17:02 Toomas75

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Feb 15 '24 19:02 ghost

This is major issue for us in big project.

https://github.com/dotnet/maui/issues/10595 https://github.com/dotnet/maui/issues/9523

Toomas75 avatar Feb 15 '24 20:02 Toomas75

It seems to me the issue is more basic. Where as any change effecting a CollectionView SelectedItem(s) VisualState will result in the View losing its Selected state Style

In this demonstration video attached, you can see simply changing the items VisualState to any of its other CommonStates, the Selected style will be lost when it should return to the Selected state.

Green = Selected Orange = Focused, Red = PointerOver

There of course needs to be a priority of VisualStates, to which only one can be active at once, but its only the Selected state which appears to not be reactivated when appropriate.

https://github.com/dotnet/maui/assets/13371986/b6f61bb6-d0ba-421b-8d71-f12556e36cc5

Sadly , another simple yet seemingly misunderstood bug that might likely address loads of other reported issues if fixed https://github.com/dotnet/maui/issues/10595 https://github.com/dotnet/maui/issues/13056 https://github.com/dotnet/maui/issues/13885 etc....

axa88 avatar Mar 17 '24 04:03 axa88

@samhouts @PureWeen Please could you take another look at this. Easily testable. I also think fixing this will resolve lot of the issues.

Toomas75 avatar Mar 18 '24 18:03 Toomas75

8.0.20-nightly.10336 - issue still persist

Toomas75 avatar Mar 21 '24 10:03 Toomas75

8.0.40-nightly.10491 - no news.

Toomas75 avatar Apr 15 '24 11:04 Toomas75

The same happens if collectionview is inside RefreshView and refreshview command CanExecute =false

Toomas75 avatar Jun 04 '24 22:06 Toomas75

Hello, I would like to know if somebody found a workaround for this ? I am having nightmares trying to work with CollectionView on Windows... :( I am simply trying to be able to define Selected and Hovered background color but as discussed here the Selected visual state is lost everytime something happens like moving the cursor away from the selected item. Thanks for any help

BeepBeepBopBop avatar Jul 19 '24 19:07 BeepBeepBopBop