Unchained Unchained - 1 year ago 80
C# Question

Set a specific height for ItemTemplate

I want set a specific height for the DropDownButton ItemTemplate, in particular, I've a lot of elements inside the DropDown Button and actually the list displayed is too long as you can see in the image below, the structure is this:

<Controls:DropDownButton Content="Nazioni" Width="120" Margin="0, 0, 20, 0"
ItemsSource="{Binding Countries}"
ItemTemplate="{StaticResource CombinedTemplate}"/>

enter image description here

Is possible set a specific height?

Answer Source

If you want to set the height of the element that is using the supplied ItemTemplate to display an item (this element is usually referred to as item container), you should use the ItemContainerStyle property (inherited from ItemsControl):

<Controls:DropDownButton (...)>
        <Style TargetType="MenuItem">
            <Setter Property="Height" Value="..." />


If you want to limit the height of the drop-down itself the way to go about it is to use the DropDownButton.MenuStyle property:

<Controls:DropDownButton (...)>
        <Style TargetType="ContextMenu" BasedOn="{StaticResource {x:Type ContextMenu}}">
            <Setter Property="MaxHeight" Value="..." />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download