Setting Column Background in WPF ListView/Gridview

后端 未结 2 1785
野趣味
野趣味 2020-12-19 00:10

I\'m looking to set the background of a column in a WPF GridView. Many Google results have pointed towards setting the GridViewColumn.CellTemplate to change the appearance o

相关标签:
2条回答
  • 2020-12-19 01:03

    Set the HorizontalContentAlignment of the ItemContainerStyle:

    <ListView ItemsSource="{Binding}">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>
    

    Result:

    alt text

    0 讨论(0)
  • 2020-12-19 01:16

    Digging up an old thread, but I found a dodgy fix for this

    <Grid Background="{Binding backGround}" Margin="-6,0,-6,0">
      <TextBlock Margin="6,0,6,0" Text="{Binding myText}" TextAlignment="Right" />
    </Grid>
    

    Moves the margins so the background color fills the entire cell, but then moves them back so the text is still in the right spot. Works for now until it's fixed properly.

    0 讨论(0)
提交回复
热议问题