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

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

Closed
dennis-benson opened this issue Apr 12, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@dennis-benson
Copy link

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 benruehl added the bug Something isn't working label Apr 13, 2019
@benruehl
Copy link
Owner

benruehl commented Apr 13, 2019

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
Copy link
Owner

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
Copy link
Author

dennis-benson commented Apr 15, 2019

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
Copy link
Owner

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
Copy link
Author

dennis-benson commented Apr 16, 2019

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
Copy link
Owner

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.

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