Open VisualAlf opened 1 week ago
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.
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.
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.
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.
'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: