How to center text in a specific column in WPF ListView?

后端 未结 1 678
深忆病人
深忆病人 2020-12-20 11:41

I tried this and also HorizontalAlignment, instead of TextAlignment but they still show up aligned to left.



        
相关标签:
1条回答
  • 2020-12-20 11:53

    Try to set HorizontalContentAlignment to Stretch for the ItemContainerStyle. Then it should work with either TextAlignment="Center" or HorizontalAlignment="Center" for the TextBlock

    <ListView ItemsSource="{Binding Effects}">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>
        <!--...-->
    </ListView>
    
    0 讨论(0)
提交回复
热议问题