如何:更改 ListView 中列的水平对齐方式

哼曲丶036
2013-10-12 · TA获得超过3093个赞
知道小有建树答主
回答量:962
采纳率:0%
帮助的人:2288万
展开全部
<!--XmlDataProvider is defined in a ResourceDictionary, such as Window.Resources--> <XmlDataProvider x:Key="InventoryData" XPath="Books"> <x:XData> <Books xmlns=""> <Book ISBN="0-7356-0562-9" Stock="in" Number="9"> <Title>XML in Action</Title> <Summary>XML Web Technology</Summary> </Book> <Book ISBN="0-7356-1370-2" Stock="in" Number="8"> <Title>Programming Microsoft Windows With C#</Title> <Summary>C# Programming using the .NET Framework</Summary> </Book> <Book ISBN="0-7356-1288-9" Stock="out" Number="7"> <Title>Inside C#</Title> <Summary>C# Language Programming</Summary> </Book> <Book ISBN="0-7356-1377-X" Stock="in" Number="5"> <Title>Introducing Microsoft .NET</Title> <Summary>Overview of .NET Technology</Summary> </Book> <Book ISBN="0-7356-1448-2" Stock="out" Number="4"> <Title>Microsoft C# Language Specifications</Title> <Summary>The C# language definition</Summary> </Book> </Books> </x:XData> </XmlDataProvider> ... <ListView ItemsSource="{Binding Source={StaticResource InventoryData}, XPath=Book}"> <ListView.View> <GridView> <GridViewColumn Width="300" Header="Title" DisplayMemberBinding="{Binding XPath=Title}"/> <GridViewColumn Width="150" Header="ISBN" DisplayMemberBinding="{Binding XPath=@ISBN}"/> </GridView> </ListView.View> </ListView> 若要更改 ISBN 列的对齐方式,需要指定每个 ListViewItem 的 HorizontalContentAlignment 属性为 Stretch,这样每个 ListViewItem 中的元素就可以跨越或占据每个列的整个宽度。 <!--The Style and DataTemplate are defined in a ResourceDictionary, such as Window.Resources--> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> </Style> <DataTemplate x:Key="ISBNTemplate"> <TextBlock HorizontalAlignment="Right" Text="{Binding XPath=@ISBN}"/> </DataTemplate> ... <ListView ItemsSource="{Binding Source={StaticResource InventoryData}, XPath=Book}"> <ListView.View> <GridView> <GridViewColumn Width="300" Header="Title" DisplayMemberBinding="{Binding XPath=Title}"/> <GridViewColumn Width="150" Header="ISBN" CellTemplate="{StaticResource ISBNTemplate}"/> </GridView> </ListView.View> </ListView>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式