如何在一个列表视图列中左对齐标题文本? [英] How can I left-align the header text in just one listview column?

查看:109
本文介绍了如何在一个列表视图列中左对齐标题文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有三列的 ListView 。前两个的宽度变化不大(总是包含相同数量的字符)。如果需要,我可以修复这些列的宽度。



第三列包含可以是任意长度的注释。我希望此列可以拉伸以填充可用空间,以尽可能多地显示注释。我可以通过给列的宽度 Auto 来做到这一点,但是标题文本总是居中,因此从右边缘消失。



问题变得更糟,因为 ListView 是使用网格制作的中心(三个)面板,我希望这个中央面板能够随着窗口大小的变化而增长和缩小。



我该怎么做?



我的尝试:



我试过以下各种例子但似乎没有工作。



这是我目前的代码,不起作用,但我不明白为什么:



I have a ListView with three columns. The first two have widths that don't change much (always contain the same number of characters). I can fix the widths of these columns if necessary.

The third column contains notes that can be any length. I would like this column to stretch to fill available space, to display as much of the note as possible. I can do this by giving the column a width of Auto, but the header text is always centred and so disappears off the right-hand edge.

The problem is made worse because this ListView is the centre (of three) panels made using a Grid, and I would like this central panel to be the one that grows and shrinks as the window size is changed.

How can I do this?

What I have tried:

I have tried following various examples but none seems to work.

This is my current code, which doesn't work, but I don't understand why:

<ListView Grid.Row="0" Grid.Column="1" SelectionMode="Single" ItemsSource="{Binding EnquiryJobsFiltered}">
	<ListView.View>
		<GridView>
			<GridViewColumn Header="Enquiry/Job" Width="90" DisplayMemberBinding="{Binding EnquiryJobNumberAsString}"/>
			<GridViewColumn Header="Progress" Width="90" DisplayMemberBinding="{Binding Progress}"/>
			<GridViewColumn>
				<GridViewColumn.HeaderTemplate>
					<DataTemplate>
						<TextBlock Text="Description" TextAlignment="Left"/>
					</DataTemplate>
				</GridViewColumn.HeaderTemplate>
				<GridViewColumn.CellTemplate>
					<DataTemplate>
						<TextBlock Text="{Binding Description}" TextAlignment="Left"/>
					</DataTemplate>
				</GridViewColumn.CellTemplate>
			</GridViewColumn>
		</GridView>
	</ListView.View>
</ListView>

推荐答案

它应该像添加 HeaderContainerStyle一样简单并将 Horizo​​ntalContentAlignment 设置为

It should be as simple as adding a HeaderContainerStyle and setting the HorizontalContentAlignment to Left:
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}">
    <GridViewColumn.HeaderContainerStyle>
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
        </Style>
    </GridViewColumn.HeaderContainerStyle>
</GridViewColumn>



操作方法:具有左对齐列名的ListView [ ^ ]


这篇关于如何在一个列表视图列中左对齐标题文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆