Community.VisualStudio.Toolkit
Community.VisualStudio.Toolkit copied to clipboard
toolkit:Themes.UseVsTheme breaks gridview header
I am using a VSIX and wanted to test a GridView inside a ListView. But whenever I did it the header of the gridview was missing.
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
toolkit:Themes.UseVsTheme="True"
<Grid Grid.Row="1">
<ListView ItemsSource="{Binding Persons}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}"/>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>

After hours of debugging I finally stumbled across the toolkit:Themes.UseVsTheme. When I removed it, everything went fine. The header was displayed again.
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
~toolkit:Themes.UseVsTheme="True"~
<Grid Grid.Row="1">
<ListView ItemsSource="{Binding Persons}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}"/>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>

This is caused by the Microsoft.VisualStudio.PlatformUI.ThemedDialogStyleLoader.UseDefaultThemedDialogStyles attached property (which the UseVsTheme property internally sets enables). If you don't use Themes.UseVsTheme and instead set the UseDefaultThemedDialogStyles directly, you'll see the same problem:
<ListView
xmlns:platform="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
platform:ThemedDialogStyleLoader.UseDefaultThemedDialogStyles="True">
</ListView>
I guess an internal Visual Studio style is removing the headers for a reason.
Unfortunately setting that attached property to false on the ListView doesn't have any effect when something above it has already enabled the default themed dialog styles (enabling the themed dialog styles causes a resource dictionary to be loaded so it applies to that element and all descendants).
I think the only option is to redefine the ControlTemplate for the ListView so that it has a header.
I am having the same problem. Dave, do you have an example how to redefine the ControlTemplate?