tkawa
Topic Author
Posts: 16
Joined: 07 Nov 2018, 05:34

[c++]About Style of ListViewItem

08 Oct 2019, 13:07

Hi,

I found two different behaviors regarding the style of TextBlock created when specifying "DisplayMemberBinding".
・ VerticalAlignment of created TextBlock is not "Center" by default
・Style defined in Resources is not reflected
Check the code below.
<ListView Grid.Row="3" FontSize="12pt" ItemsSource="{Binding ItemList}">
    <ListView.Resources>
        <Style TargetType="TextBlock" >
            <Setter Property="Background" Value="Red"/>
        </Style>
    </ListView.Resources>
    <ListView.View>
        <GridView>
            <GridViewColumn Header="ColA" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Header="ColB">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Grid Height="50">
                            <TextBlock Text="{Binding Path=Name}"/>
                        </Grid>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="ColC">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Grid Height="50">
                            <Grid.Resources>
                                <Style TargetType="TextBlock" >
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="Background" Value="LightBlue"/>
                                </Style>
                            </Grid.Resources>
                            <TextBlock Text="{Binding Path=Name}"/>
                        </Grid>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

        </GridView>
    </ListView.View>
</ListView>
Attachments
noesis.png
NoesisGUI
noesis.png (4.64 KiB) Viewed 389 times
wpf.png
WPF
wpf.png (7.51 KiB) Viewed 389 times

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: [c++]About Style of ListViewItem

10 Oct 2019, 11:10

Hi,

The vertical alignment difference comes from our default style for the ListViewItem, that sets VerticalContentAlignment to Stretch, while Windows is setting it as Center.
You can override that value from the default style specifying a new Style:
<ListView Grid.Row="3" FontSize="12pt" ItemsSource="{Binding ItemList}">
    <ListView.Resources>
        <Style TargetType="TextBlock" >
            <Setter Property="Background" Value="Red"/>
        </Style>
        <Style TargetType="ListViewItem">
            <Setter Property="VerticalContentAlignment" Value="Center"/>
        </Style>
    </ListView.Resources>
    ...
The problem with generated TextBlocks from DisplayMemberBinding is a bug in our code, could you please report it?
It is incorrectly doing the resource look up only in the ListViewItem scope.
 
tkawa
Topic Author
Posts: 16
Joined: 07 Nov 2018, 05:34

Re: [c++]About Style of ListViewItem

16 Oct 2019, 05:14

Thank you, I reported the issue here: #1570
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: [c++]About Style of ListViewItem

16 Oct 2019, 12:34

Thanks for the report.

Who is online

Users browsing this forum: Google [Bot] and 1 guest