benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.71k stars 143 forks source link

NullReferenceException when clicking the 'empty space' in the GridView column headers #21

Closed dennis-benson closed 5 years ago

dennis-benson commented 5 years ago

Quick and dirty fix is to add a null check, but it seems to make sense if that header wasn't there, or wasn't selectable.

benruehl commented 5 years ago

Got it reproduced now, thanks for reporting. This seems to occur in case the GridView.Columns are not specified. I will add a null check at least and see whether it makes sense to collapse.

benruehl commented 5 years ago

May I ask what your use case for this setup is? Using a ListView but not specifying any columns sounds to me like a ListBox is what you really want.

dennis-benson commented 5 years ago

I was reporting the bug based on the demo.

In my project, I was specifying columns in a ListView

<GridView>
    <GridViewColumn Header="Name">
          ...
     </GridViewColumn>
     <GridViewColumn Header="Age">
           ...
      </GridViewColumn>
</GridView>

It seems to be a problem only when HorizontalOptions is set to stretch - which I suppose WPF doesn't like

benruehl commented 5 years ago

I am not quite sure what you mean. I do not get any exception in the demo when clicking on a GridViewHeader so it would be helpful if you could explain it a bit further.

In which exact scenario do you get an exception? Is the code you posted causing errors or is this working code? And what do you mean with "when HorizontalOptions is set to stretch"? Do you mean HorizontalAlignment? And if so, where do you set it to Stretch?

In order to fix it, I need to reproduce it. I indeed got errors when there are no columns defined. And that is what i have fixed. If you still get errors because you mean a different scenario please tell me what I have to do in order to get the errors as well.

dennis-benson commented 5 years ago

Sorry, I thought it'd be easy to reproduce :)

If the columns don't fill all the available space, a "clickable phantom header" is visible (see screenshot and xaml) - clicking it produces a crash.

crasher

                         <TabItem Header="Grid View">
                            <ListView ItemsSource="{Binding Items}">
                                <ListView.View>
                                    <GridView>
                                        <GridView.Columns>
                                            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
                                            <GridViewColumn Header="Weight"
                                                    DisplayMemberBinding="{Binding Weight, StringFormat=N2}"/>
                                        </GridView.Columns>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </TabItem>

It appears that the phantom header is extends from "Name" to the edge of the container. The best way to hide it is by adjusting the column width to fill space, or adjusting the listview width to fit the columns.

benruehl commented 5 years ago

Thank you for taking the time to add some details. Now it makes sense to me what you meant with "empty space". I did not really get that before although it seems quite obvious now. But I am glad that the null check fixes that already, even though it targeted a different case :)

Stretching the columns to eliminate the empty space is not possible with simple XAML as far as I know. Maybe I could build another extension for that in a future version if you would like to see this.