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>