Hello folks,
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.
- The Items/fonts have a different height
- 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?
- 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!