Skip to content
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

SelectionMode=Multiple, no checkboxes #50

Open
VisualAlf opened this issue Oct 18, 2024 · 4 comments
Open

SelectionMode=Multiple, no checkboxes #50

VisualAlf opened this issue Oct 18, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@VisualAlf
Copy link

'Multiple' should show checkboxes for each row. However if I start with this SelectionMode, either the ShowOptionsButton or the SelectAllButton is shown in the upper left corner. While there should be the selectAllCheckBox. Also no Boxes for any row.

Only, if I start with any other Mode (None, Single, or Extended) and then change the value via Hot Reload to be Multiple, the checkboxes will be shown.

Current values are:

SelectionMode=Multiple
IsReadOnly=True
SelectionUnit=Row
ShowOptionsButton=False
CanReorderItems=False

@VisualAlf VisualAlf added the bug Something isn't working label Oct 18, 2024
@VisualAlf
Copy link
Author

At least a caveat (or a workaround, I just found about) :
I had the settings (like above) within a Style. If I put SelectionMode directly into the TableView definition, it truly sets the property. Also if I set SelectionMode in a Loaded method.

Don't know if this is a 'Feature' from WinUI, or if there can be something done about that.
SelectionMode, btw., seems to be the only property with that behavior.

@w-ahmad
Copy link
Owner

w-ahmad commented Oct 20, 2024

Thank you @VisualAlf for your feedback and findings. I tried setting these properties in few different ways but every time it works well for me. It would be helpful if you could share a code snippet that reproduces this issue.

@VisualAlf
Copy link
Author

as I wrote in my previous comment, the problem stems from usage of Style.
To reproduce amend the original SampleApp like so:

    <Grid Loaded="OnRootGridLoaded" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
        <Grid.Resources>
            <converters:StringFormatConverter x:Key="StringFormatConverter" />

            <!-- this style packs common settings -->
            <Style x:Key="LookupTable" TargetType="table:TableView">
                <Setter Property="IsReadOnly" Value="True" />
                <Setter Property="SelectionUnit" Value="Row" />
                <Setter Property="AutoGenerateColumns" Value="False" />
                <Setter Property="CanReorderItems" Value="False" />
                <Setter Property="SelectionMode" Value="Single" /> 
            </Style>

        </Grid.Resources>
        <Grid.RowDefinitions>
            ... 
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
             ....
        </StackPanel>
       
        <!-- Here all the settings come from the style. 
               Note, that SelectionMode will stay at 'Extended' instead of 'Single' -->
        <table:TableView x:Name="tableView"
                         Grid.Row="1"
                         Margin="16"
                         Style="{StaticResource LookupTable}"
                         >

            <table:TableView.Columns>
               ....

Put a Breakpoint on any Buttonhandler and inspect tableView.SelectionMode.
It is stuck at 'Extended', regardless of what value you'll give at the Style.

However, if you move SelectionMode out of the Style and set the prop at the TableView directly, it will work. Like so:

        <table:TableView x:Name="tableView"
                         Grid.Row="1"
                         Margin="16"
                         SelectionMode="Single"
                         Style="{StaticResource LookupTable}"
                         ....

This is also, what happens if we set SelectionMode=Multiple. There won't be any checkboxes, since this SelectionMode doesn't make it to the tableview. If we proceed as above, however, the issue as mentioned in the title is gone.

I don't know if this is a 'Feature' in WinUI, or if there can be something done about that. It certainly doesn't feel OK, anyway.

@w-ahmad
Copy link
Owner

w-ahmad commented Oct 22, 2024

Thank you, @VisualAlf, for the detailed explanation.

The SelectionMode property is defined in TableView and is also present in its base class. WinUI seems unable to set properties that are declared twice or to hide the base class property using the new keyword. The reason why TableView hidesSelectionMode property because it supports two types of selection: Rows and Cells.

For instance, if SelectionUnit is set to Cell and SelectionMode is set to Extended, then it should prevent row selection, and to do that SelectionMode of ListView is set to None. This approach was devised during the early development stages of cell selection when row selection was not managed within TableView. Now in v1.2.1, TableView independently handles both cell and row selection, hiding base SelectionMode` property is unnecessary. I will remove this property in upcoming release.

It might be worthwhile to open an issue in the WinUI repository to highlight this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants