wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Fix ListView to be compatible when ListView.View is a GridView

Open koal44 opened this issue 11 months ago • 1 comments

The UI library currently breaks all ListView controls that use the GridView view. This PR adds support for GridView and showcases it in the GalleryApp

Pull request type

  • [x] Bugfix
  • [x] Feature

What is the current behavior?

The current behavior is that UI library interferes with how different derived types of BaseView are dynamically stylized, which renders types like GridView incompatible with this library. Although you can workaround this by voiding the library's styles, something like:

<ListView Style="{x:Null}">
   <ListView.Resources>
      <Style TargetType="ListViewItem"> <Setter Property="Background" Value="Transparent" /> </Style>
   </ListView.Resources>
   <ListView.View>
      <GridView><GridViewColumn DisplayMemberBinding="{Binding ...}" /></GridView>
   </ListView.View>
</ListView>

Digging through older framework code, it appears that when View changes, ListView uses the current View to change its own DefaultStyleKey and also apply new keys to its viewitem children. When the View is null, the DefaultStyleKey will point to ListBox and ListBoxItem (theme styles) and for GridView it'll be GridViewStyle and GridViewItemContainerStyle. When this library directly set a style on ListView and ListViewItem it broke the unorthodox approach the framework used to dynamically set styles to different views.

My first attempt was to go with the flow of the WPF framework. For example, you should be able to style ListBox and see that refelcted in a ListView with null View, but various attempts at this failed.

Since there is actually only one derived type of BaseView - namely GridView, there are effectively only two scenarios that exist - nullview and gridview, so we can use a more standard approach and use xaml styles to handle these two different cases.

What is the new behavior?

  • Extend ListView so that we can subscribe to changes in View
  • Use triggers in ListView.xaml and ListViewItem.xaml to adapt to different View states
  • Add a sample to the the Gallery app

Other information

image

koal44 avatar Feb 28 '24 00:02 koal44

Just wanted to add there seems to be a few open issues relevant to this bugfix: #918 #436 #198

koal44 avatar Feb 28 '24 01:02 koal44

Hey @koal44 , thanks for your contribution to the project. I would add some documentation and improve the formatting

pomianowski avatar Mar 11 '24 12:03 pomianowski

I force pushed the last commit so that it aligned better with Wpf.Ui/development.

The latest commit removes the custom ui:ListView class that was previously introduced in this PR. The purpose of the class was to expose the ListView's view state (either "Default" or "GridView") but XAML can bind just as easily to the standard ListView.View property with a ValueConverter.

I didn't mention it before, but the XAML style for GridView was adapted from the Aero2 theme with slight changes to fit this project's aesthetics. The GridViewColumnHeader's padding and margins were eyeballed to fit with the GalleryApp and should probably be reviewed so that alignment is consistent between header columns and data columns for all user apps.

koal44 avatar Mar 14 '24 22:03 koal44

Any idea when this will be released? Would love to have this fixed instead of a work around that doesn't really work.

compil3 avatar Mar 15 '24 17:03 compil3

Ok, the recent update should address reviewer concerns about documentation and VS tooling. I also re-implemented the custom ui:ListView class as it should leave the original framework's ListView unchanged and unbugged.

koal44 avatar Mar 19 '24 15:03 koal44

Looking forward to these ListView PRs showing up in a release! This is great, thank you!

david-risney avatar Mar 25 '24 00:03 david-risney

Looking forward to these ListView PRs showing up in a release! This is great, thank you!

Hey, already released in the version 3.0.3

pomianowski avatar Mar 25 '24 09:03 pomianowski

Tried setting the IsEnabled property to false?

BingGitCn avatar Mar 30 '24 01:03 BingGitCn

Looking forward to these ListView PRs showing up in a release! This is great, thank you!

Hey, already released in the version 3.0.3

I'm trying out the latest version and its looking great! Thanks so much!

david-risney avatar Apr 01 '24 16:04 david-risney