wpfui
wpfui copied to clipboard
Fix ListView to be compatible when ListView.View is a GridView
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
andListViewItem.xaml
to adapt to different View states - Add a sample to the the Gallery app
Other information
Just wanted to add there seems to be a few open issues relevant to this bugfix: #918 #436 #198
Hey @koal44 , thanks for your contribution to the project. I would add some documentation and improve the formatting
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.
Any idea when this will be released? Would love to have this fixed instead of a work around that doesn't really work.
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.
Looking forward to these ListView PRs showing up in a release! This is great, thank you!
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
Tried setting the IsEnabled property to false?
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!