如何"中心"列中的listview项

时间:2014-04-17 01:46:30

标签: html css wpf xaml listview

似乎无论我将HorizentalAlignment = "Center"放在我的ListViewColumn中,它都不会影响结果。

这是我到目前为止所做的一切,

        <ListView.View>
            <GridView>
                <GridViewColumn Header="Device name" Width="120" DisplayMemberBinding="{Binding Path=DeviceName}"/>
                <GridViewColumn>
                    <GridViewColumnHeader Content=" GPS Signal " />
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Center">
                                <Image Width="13" HorizontalAlignment="Center" Source="{Binding Path=GpsSignalImagePath}"/>
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

正如你所看到的那样,GridImage本身也提到过,但没有运气。结果显示与左对齐,如下图所示。

enter image description here

2 个答案:

答案 0 :(得分:0)

HorizontalAlignment内设置ItemsPanelTemplate

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <Grid HorizontalAlignment="Center"/>
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

答案 1 :(得分:0)

您可以尝试从样式中设置HorizontalContentAlignment ListViewItem以更改单元格内容的对齐方式:

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