C# Listview中心文本

C# Listview中心文本,c#,wpf,xaml,listview,C#,Wpf,Xaml,Listview,可能重复: 大家好,我们如何将Wpf中listview项中的所有文本居中 <ListView x:Name="FoldersListView" Margin="57,150,161,139" Style="{DynamicResource ListViewStyle1}" Background="#FFEDDEDE" IsSynchronizedWithCurrentItem="True"> <ListView.View> <

可能重复:

大家好,我们如何将Wpf中listview项中的所有文本居中

<ListView x:Name="FoldersListView" Margin="57,150,161,139" Style="{DynamicResource ListViewStyle1}" Background="#FFEDDEDE" IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Folder" Width="300" DisplayMemberBinding ="{Binding Path = FolderPath}" />

                <GridViewColumn Header="Status" Width="100" DisplayMemberBinding="{Binding Path = FolderStatus}"/>

            </GridView>
        </ListView.View>            
    </ListView>

因为您对每列没有区别:

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
</ListView.ItemContainerStyle>


嘿,谢谢,它很管用。关于这一点,我还有一个问题。既然listview是从style=“{DynamicResource ListViewStyle1}”获取样式的,那么当我已经在@RStyle:下指定时,为什么文本本身不居中呢?基本上是因为
listview.HorizontalContentAlignment
(您的样式设置)独立于
ListViewItem.HorizontalAlignment
(需要在
ItemContainerStyle
中设置,或者在项目容器类型的隐式样式中设置)@RStyle:(刚刚注意到我无意中编写了
HorizontalAlignment
,当然,我在这两种情况下都是指
HorizontalContentAlignment
,这样就不会让人混淆了……)