Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>Two options - a.) The not-so-pretty: set a fixed height in the TextBlock or b) put the items inside a Grid like this:</p> <pre><code>&lt;ComboBox ... Grid.IsSharedSizeScope="True"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.RowDefinistions&gt; &lt;RowDefinition Height="Auto" SharedSizeGroup="Row"/&gt; &lt;Grid.RowDefinistions&gt; &lt;TextBlock .../&gt; &lt;Grid&gt; &lt;DataTemplate&gt; &lt;ComboBox.ItemTemplate&gt; </code></pre></li> <li><p>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.</p></li> <li><p>Put VerticalAlignment="Center" in the TextBlock inside the DataTemlate.</p></li> </ol> <p>Hope this helps.</p> <p>EDIT: </p> <p>Thanks :). I'll give you a few hints:</p> <p>When using the VirtualizingStackPanel, in almost all cases you should set VirtualizationMode="Recycling" - same goes for the other ItemsControls by the way:</p> <pre><code>&lt;ListBox VirtualizingStackPanel.VirtualiationMode="Recycling"/&gt; &lt;VirtualizingStackPanel VirtualizationMode="Recycling"/&gt; </code></pre> <p>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).</p> <p>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.</p> <p>If you want to color every second item in the list - you can achieve this as follows:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;Style TargetType="{x:Type ComboBoxItem}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="ItemsControl.AlternationIndex" Value="1"&gt; &lt;Setter Property="Background" Value="LightGray"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; &lt;ComboBox AlternationCount="2"&gt; </code></pre> <p>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.</p> <p>Hope, you got a few hints in there :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload