Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / Combo Box / ComboBox Features / Drop-Down List / Setting the Maximum Height and Width
In This Topic
    Setting the Maximum Height and Width
    In This Topic

    By default, the size of the drop-down list is determined by the width of the widest C1ComboBoxItem item and the collective height of all of the C1ComboBoxItem items, as the DropDownWidth and DropDownHeight properties are both set to NaN.

    You can control the maximum width and maximum height of the drop-down list by setting the C1ComboBox control's MaxDropDownWidth and MaxDropDownHeight properties. Setting these properties ensures that the area of the drop-down list can never expand to a larger area than you've specified. If the width or height of the list exceeds the specified maximum height and width, scrollbars will automatically be added to the drop-down list. 

    Complete the following steps:

    1. Add MaxDropDownHeight="150" and MaxDropDownWidth="350" to the <c1:C1ComboBox> tag so that the markup resembles the following:
    XAML
    Copy Code
    <c1:C1ComboBox HorizontalAlignment="Left" Width="249" MaxDropDownHeight="150" MaxDropDownWidth="350">.
    
    1. Run the program and click the combo box's drop-down arrow to see the result of your settings.

    Complete the following steps:

    1. Add x:Name="C1ComboBox1" to the <c1:C1ComboBox> tag so that the object will have a unique identifier for you to call in code.
    2. Open the MainPage.xaml.cs page.
    3. Add the following code beneath the InitializeComponent() method to set the DropDownHeight property :
    Visual Basic
    Copy Code
    C1ComboBox1.MaxDropDownHeight = 150
    

    C#
    Copy Code
    C1ComboBox1.MaxDropDownHeight = 150;
    
    1. Add the following code beneath the InitializeComponent() method to set the DropDownWidth property :
    Visual Basic
    Copy Code
    C1ComboBox1.MaxDropDownWidth = 350
    

    C#
    Copy Code
    C1ComboBox1.MaxDropDownWidth = 350;
    
    1. Run the program and click the combo box's drop-down arrow to see the result of your settings.

    Complete the following steps:

    1. Click the C1ComboBox control once to select it.
    2. In the Properties window, complete the following:
    • Set the MaxDropDownHeight to a value, such as "150".
    • Set the MaxDropDownWidth to a value, such as "350".
    1. Run the program and click the combo box's drop-down arrow to see the result of your settings.