如何:更改 ListView 中列的水平对齐方式
展开全部
<!--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>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询