WPF-DataGrid设置各行变色

我在stackoverflow.com中找到的资料:我在stackoverflow.com中找到的资料:


he ItemContainerStyle is applied to the elements generated by the ItemsControl: ContentPresenter. The ContentPresenter will in turn contain whatever you put in your ItemTemplate. In the case of a ListBox, the ItemContainerStyle is applied to the generated ListBoxItem.

The AlternationCount is, based on what you posted, only available on these generated items. You cannot use the ItemContainerStyle to set the Grid's background, because the Grid is unknown to that Style.

The following would be ideal, but unfortunately ContentPresenter has no background property. It would work for a ListBox (with ListBoxItems) however.


    
        
    

So you end up writing a style for the grid which binds to the AlternationIndex of your parent ContentPresenter.


    
        
            
        
    

作者:Bubblewrap
网址:http://stackoverflow.com/questions/3567778/how-to-use-alternationindex-in-itemscontrols
--------------------------------------------------------------------------------------------------


我自己的实践:








希望对大家有所帮助。

你可能感兴趣的:(WPF)