locked
Get the row height of a listview RRS feed

  • Question

  • I need to know how I can retrieve the height of a row of a listview item (assuming that I am not using any custom datatemplate). I am trying to populate a listview with only that many rows which it would be able to display ... hence need to know the heights of individual rows to arrive to an estimate.
    Thursday, January 6, 2011 5:25 AM

Answers

  • Hi xl3k,

    Welcome to our forum.

    Based on your description I am not sure why you want to "measure the height before adding the item", I think you could define the Height of the ListView like below code snippet:

    <ListView>
    <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
    <Setter Property="Height" Value="50 Or Auto" />
    </Style>
    </ListView.ItemContainerStyle>
    <!-- WHATEVER -->
    </ListView>

    On the other hand, if you want to get the Row Height of ListView, you could refer to this thread:

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/446cd40b-ec43-4e9f-a2cc-ee6932fd09a9/

    Then you could base on all the row Height to "Figure out how many more could be added".

    If your issue persists, please let me know.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Friday, January 14, 2011 12:51 PM
    Monday, January 10, 2011 9:29 AM

All replies

  • Hi,

    You want to measure the height before adding the item or after adding the item? you can Iterate through each ListViewItem and the get the actualHeight property to analyze things.

     


    Md. Masudur Rahman
    Thursday, January 6, 2011 3:30 PM
  • I would like to get it before adding any item, but then if it is absolutely impossible, I can add a row and then should be able to figure out how many more could be added.
    • Edited by xl3k Friday, January 28, 2011 10:28 AM absolutely -> absolutely impossible
    Friday, January 7, 2011 9:23 AM
  • Hi xl3k,

    Welcome to our forum.

    Based on your description I am not sure why you want to "measure the height before adding the item", I think you could define the Height of the ListView like below code snippet:

    <ListView>
    <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
    <Setter Property="Height" Value="50 Or Auto" />
    </Style>
    </ListView.ItemContainerStyle>
    <!-- WHATEVER -->
    </ListView>

    On the other hand, if you want to get the Row Height of ListView, you could refer to this thread:

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/446cd40b-ec43-4e9f-a2cc-ee6932fd09a9/

    Then you could base on all the row Height to "Figure out how many more could be added".

    If your issue persists, please let me know.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Friday, January 14, 2011 12:51 PM
    Monday, January 10, 2011 9:29 AM
  • Hi xl3k,

    I am marking your issue as "Answered", if you have new findings about this issue, please unmark.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 14, 2011 12:51 PM