[c++]About Style of ListViewItem
Posted: 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.
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.
Code: Select all
<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>