Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:48:29+00:00 2026-05-16T07:48:29+00:00

I have this code: <ComboBox Width=100 ItemsSource={Binding FontList} x:Name=fontComboFast> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate>

  • 0

I have this code:

  <ComboBox Width="100" ItemsSource="{Binding FontList}" x:Name="fontComboFast">
                        <ComboBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel />
                            </ItemsPanelTemplate>
                        </ComboBox.ItemsPanel>
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" FontFamily="{Binding }" FontSize="12" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

There are 3 gotchas in that Combobox.

  1. The Items/fonts have a different height
  2. When I scroll up/down the scrollviewer`s width increases/decreases depending on the Length of the longest visible item in the scrollviewer. How can I set a fixed width?
  3. The fonts aka TextBlocks are not vertically centered

How can I change those 3 things?

UPDATE:

 <ComboBox AlternationCount="2" Width="200"  ItemContainerStyle="{StaticResource alternateColor}" ItemsSource="{Binding Source={x:Static Member=Fonts.SystemFontFamilies}}" x:Name="fontComboFast">

<Style x:Key="alternateColor" TargetType="{x:Type ComboBoxItem}">
            <Style.Setters>
                <Setter Property="Height" Value="30" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="FontSize" Value="16" />
            </Style.Setters>
            <Style.Triggers>                
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="LightGray"/>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="AliceBlue"/>
                </Trigger>                
            </Style.Triggers>
        </Style>

Hm 2 of 3 answers were right and they were the easiest ones is this now a solution? :O
You have some cool combobox tips in store? Then I would mark it as solution else you get a point 😉

btw. congrats to your new wpf job read it on your blog, I envy you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:48:29+00:00Added an answer on May 16, 2026 at 7:48 am
    1. Two options – a.) The not-so-pretty: set a fixed height in the TextBlock or b) put the items inside a Grid like this:

      <ComboBox ... Grid.IsSharedSizeScope="True">
          <ComboBox.ItemTemplate>
              <DataTemplate>
                  <Grid>
                      <Grid.RowDefinistions>
                          <RowDefinition Height="Auto" SharedSizeGroup="Row"/>
                      <Grid.RowDefinistions>
                      <TextBlock .../>
                   <Grid>
               <DataTemplate>
           <ComboBox.ItemTemplate>
      
    2. Again – two options: a) Set a fixed width of the TextBlock in the DataTemplate. b) If you replace the VirtualizingStackPanel with a StackPanel and do the same for the ColumnDefinition above (this will be a performance problem if you have a lot in your list as it will create all visual elements when loading.

    3. Put VerticalAlignment=”Center” in the TextBlock inside the DataTemlate.

    Hope this helps.

    EDIT:

    Thanks :). I’ll give you a few hints:

    When using the VirtualizingStackPanel, in almost all cases you should set VirtualizationMode=”Recycling” – same goes for the other ItemsControls by the way:

    <ListBox VirtualizingStackPanel.VirtualiationMode="Recycling"/>
    <VirtualizingStackPanel VirtualizationMode="Recycling"/>
    

    This will recycle the DataTemplate’s when the user scrolls through the list. Especially in large datasets or with complex DataTemplates this will give a considerable smoother experience. IsEditable=”True” destroys this benefit (It’s a known bug).

    Normally when you only want to use one property as the DataTemplate, you can use the DisplayMemberPath – and this will give you keyboard accelerators (typing ‘T’ will scroll to the first item beginning with T etc.) If you use DataTemplates – you can achieve the same by using TextSearch.TextPath. Just remember to sort the items in the combobox to the same property that you use in the TextPath – otherwise, users are in for a ‘bumpy’ experience as it will seemingly randomly jump about the list.

    If you want to color every second item in the list – you can achieve this as follows:

    <UserControl.Resources>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="LightGray"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <ComboBox AlternationCount="2">
    

    Actually, I don’t really use the ComboBox that much – mostly, I use it for Enum-values and very small datasets. The problem with the ComboBox is that it supports paging very poorly – with large datasets I normally use the AutoCompleteBox from the WPF Toolkit or a ListBox with a TextBox above it for filtering.

    Hope, you got a few hints in there 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that adjusts the width of a comboBox drop-down: private void
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
I have this code: con.Open(); cmd = new MySqlCommand(String.Format(SELECT concat(name,'|',lastname) FROM {0} WHERE ID=
I have a combo box defined as such <ComboBox Name=RoomDropDown Visibility={Binding Path=RoomDropDownVisible,Mode=OneWay,Converter={StaticResource BoolVisibilityConvertor}} ItemsSource={Binding
I have a combo box defined as such <ComboBox Name=RoomDropDown Visibility={Binding Path=RoomDropDownVisible,Mode=OneWay,Converter={StaticResource BoolVisibilityConvertor}} ItemsSource={Binding
I have two forms, a combobox is populated on both forms with this code
Assume I have this html code: <select id=superior size=1 name=superior> <option value=></option> <option value=c.i.e.m.md.Division_1>DIVISION007</option>
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.