locked
ListViewItem's MaxHeight acts as Height instead? RRS feed

  • Question

  • In the Windows Store 8.1 (Preview) XAML/C# project I've got a ListView whose items may have a varying height (depending on the content), which I want to limit to a maximum value.

    The problem seems to be that:

    • If I don't specify any Height restriction in the ListView definition, the items in the list are rendered with dynamic heights, as expected.
    • If I specify only the MinHeight (for ListView.ItemContainerStyle with TargetType="ListViewItem"), the items in the list are still rendered with dynamic heights, as expected, with the minimum height respected.
    • But if I specify the MaxHeight similarly, all the list items are rendered with the same fixed height.

    Is there a framework implementation problem here, or am I missing something fundamental about how these properties are supposed to work?

    And in any case, what would be the proper way (or the workaround if there isn't such a way) to achieve the desired goal of having dynamically sized items up to a max height?

    Tuesday, October 1, 2013 3:32 PM

Answers

  • Hi KHK,

    I cannot reproduce the problem with Windows Store 8.1 RTM.

    Setting an ItemContainerStyle with MinHeight and MaxHeight works as expected: my smaller items increase to MinHeight and my larger items decrease to MaxHeight. Items in the middle use their own height.

    Here's a quick test snippet:

            <ListView  >
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                    <Setter Property="MinHeight" Value="100" />
                    <Setter Property="MaxHeight" Value="300" />
                    </Style>
                </ListView.ItemContainerStyle>
                    <Rectangle Fill="Red" Height="50" Width="300" />
                    <Rectangle Fill="Orange" Height="150" Width="300" />
                    <Rectangle Fill="Yellow" Height="200" Width="300" />
                    <Rectangle Fill="Green" Height="800" Width="300" />
                    <Rectangle Fill="Blue" Height="75" Width="300" />
                    <Rectangle Fill="Indigo" Height="700" Width="300" />
                    <Rectangle Fill="Violet" Height="170" Width="300" />
            </ListView>

    --Rob

    Tuesday, October 1, 2013 11:36 PM
    Moderator