欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF 如何统一设置ListView中GridViewColumn的Style

程序员文章站 2022-03-01 13:04:23
...

原先代码,如果GridViewColumn多了要写多次,很麻烦:

<ListView>
	<ListView.View>
		<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnStyle}">
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
				<GridViewColumn Style={StaticResource GridViewColumnStyle}/>
		</GridView>
	</ListView.View>
</ListView>

只需要GridView中设置一下ColumnHeaderContainerStyle即可:

<ListView>
	<ListView.View>
		<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnStyle}">
				<!--省略GridViewColumn-->
		</GridView>
	</ListView.View>
</ListView>

相关标签: WPF