WPF Datagrid/Listview INVERTED?

喜你入骨 提交于 2020-01-06 13:11:30

问题


Is Possible to get a datagrid (or listview) control inverted? For example, usually we have a listview like this:

Name Age Job

John 23 eng

Now I want to invert the table:

Label 1col

Name John

Age 23

Job eng

Thus we can able to select the single column...


回答1:


Current WPF DataGrid dioes not perform this straight away...

But there are options...

XML Way

XML format of data can help you to achieve this.

e.g

        <Employees>
            <Employee>
               <FirstName>A</FirstName>
               <LastName>B</LastName>
            </Employee>
            <Employee>
               <FirstName>C</FirstName>
               <LastName>D</LastName>
            </Employee>
            <Employee>
               <FirstName>P</FirstName>
               <LastName>Q</LastName>
            </Employee>
        </Employees>

needs to be transformed using an XSLT that converts it into something like this...

        <Columns>
           <Column Name="FirstName">
               <Employee>A</Employee>
               <Employee>C</Employee>
               <Employee>P</Employee>
           </Column>
           <Column Name="LastName">
               <Employee>B</Employee>
               <Employee>D</Employee>
               <Employee>Q</Employee>
           </Column>
        </Columns>

The column headers has to be overriden by styles that hide the column header names when transformation takes place.

Also RowHeader has to be styled to "steal" names /Column@Name in the same order as they appear in the data.

Rotate Transform Way

Roate the data grid in 90 degreess and each cell content in 270 degrees. Dont know if Layout or Render transform gives better results...

Let me know if this guides you in correct direction.




回答2:


In google I find this fantastic solution:

http://blogs.microsoft.co.il/blogs/tomershamam/archive/2008/09/22/lt-howto-gt-replace-listview-columns-with-rows-lt-howto-gt.aspx



来源:https://stackoverflow.com/questions/7646053/wpf-datagrid-listview-inverted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!