[c++]About Style of ListViewItem
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>
- Attachments
-
- NoesisGUI
- noesis.png (4.64 KiB) Viewed 2667 times
-
- WPF
- wpf.png (7.51 KiB) Viewed 2667 times
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: [c++]About Style of ListViewItem
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:
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.
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:
Code: Select all
<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>
...It is incorrectly doing the resource look up only in the ListViewItem scope.
Re: [c++]About Style of ListViewItem
Thank you, I reported the issue here: #1570
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: [c++]About Style of ListViewItem
Thanks for the report.
Who is online
Users browsing this forum: No registered users and 3 guests