Search code examples
wpflistboxlistboxitem

How do I set ListBox item height in Window Resources?


This

<ListBox x:Name="gLBxM">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Height" Value="21" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox> 

sets the ListBox item height for a specific ListBox. What do add to

<Window.Resources> 

so it applies to all ListBox'es?


Solution

  • The following implicit Style will be applied to all ListBoxItems in the window unless you set the ItemContainerStyle property to some other Style:

    <Window.Resources>
        <Style TargetType="ListBoxItem">
            <Setter Property="Height" Value="100" />
        </Style>
    </Window.Resources>
    ...
    <ListBox x:Name="gLBxM" />