Community.VisualStudio.Toolkit icon indicating copy to clipboard operation
Community.VisualStudio.Toolkit copied to clipboard

toolkit:Themes.UseVsTheme breaks gridview header

Open JGT90 opened this issue 2 years ago • 2 comments
trafficstars

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>

image

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>

image

JGT90 avatar Dec 06 '22 10:12 JGT90

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.

reduckted avatar Dec 17 '22 09:12 reduckted

I am having the same problem. Dave, do you have an example how to redefine the ControlTemplate?

RobertvanderHulst avatar Jun 12 '23 14:06 RobertvanderHulst