biju
biju

Reputation: 18000

How to get the wpf listboxitem to stretch entire height of listbox when selected

How can i get the listbox item to stretch the entire height of the listbox when it is selected.My situation is like my listboxitem contains an expander which expands and shows another list.The second listbox is quite long and i am looking for some way to prevent the user from scrolling a lot.I am looking for some way to give the second listbox the entire height available.Any inputs will be highly appreciated.Thanks in advance.

Upvotes: 2

Views: 1334

Answers (1)

Jefim
Jefim

Reputation: 3077

I am not sure if I got the idea correctly, but try this:

    <ListBox>
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Height" Value="{Binding Path=ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
    </ListBox>

Upvotes: 3

Related Questions