dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.23k stars 1.76k forks source link

CollectionView (Windows) item height and selection #10036

Open mike3sullivan opened 2 years ago

mike3sullivan commented 2 years ago

Description

On Windows, CollectionView items have a not-so-well-hidden checkbox as part of the item that messes up the layout. It affects minimum height as well as horizontal positioning of the item. This is a major problem when trying to use a multiple-selection CollectionView for a text list display (because the ListView doesn't support multi-selection).

Steps to Reproduce

Code snippet below supported by simple ObservableCollection<string> data exposes hidden checkbox and minimum height.

Screenshot 2022-09-10 093011

The top CollectionView has a green background on the items, the bottom without. I have used padding and margin to push highlight the checkbox separate from the text.

By default the text is shifted right but still overlaps a bit of the checkbox, and when selected, leaves a white checkmark over the start of the text. If you shift the text left, that white checkmark makes the text difficult to read. Screenshot 2022-09-10 094926

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiAppCollectionViewItem.MainPage">
    <StackLayout>
        <CollectionView 
            ItemsSource="{Binding Data}" SelectionMode="Multiple"
            WidthRequest="250" HorizontalOptions="Start" VerticalOptions="Start"
            BackgroundColor="White">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="-20,0,0,0" Padding="0" BackgroundColor="Green" VerticalOptions="Center">
                        <Label Padding="30,0,0,0" Margin="0" Text="{Binding}" VerticalOptions="Center"  />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <CollectionView 
            ItemsSource="{Binding Data}" SelectionMode="Multiple"
            WidthRequest="250" HorizontalOptions="Start" VerticalOptions="Start"
            BackgroundColor="White">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="-20,0,0,0" Padding="0" VerticalOptions="Center">
                        <Label Padding="30,0,0,0" Margin="0" Text="{Binding}" VerticalOptions="Center"  />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </StackLayout>

</ContentPage>

Link to public reproduction project repository

https://github.com/mike3sullivan/MauiAppCollectionViewItem

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10

Did you find any workaround?

no workaround found.

Relevant log output

No response

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

jefffeely commented 2 years ago

I hope this and other Windows Desktop issues will be given a high priority once you get around to processing the backlog. CollectionView not working properly is keeping me from using MAUI, along with all the other bugs.

ToolmakerSteve commented 1 year ago

Here is a StackOverflow question, similarly showing that CollectionView of a Label has an undesirable height per item:

https://stackoverflow.com/questions/76248220/label-height-in-a-collectionview-datatemplate

daltzctr commented 1 year ago

Any update on this? It makes making a compressed layout (such for rapid data entry) difficult. Any workarounds?

Zhanglirong-Winnie commented 1 year ago

Verified this issue with Visual Studio 17.7.0 Preview 1.0. Can repro on windows platform with above project. MauiAppCollectionViewItem-main.zip Screenshot 2023-05-25 144148