Reputation: 5143
This is my Xaml
:
<Style TargetType="ComboBox">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="Margin" Value="5" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="5" />
<Setter Property="FontSize" Value="20" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="White" />
</Style>
<Style TargetType="TextBox">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Margin" Value="5" />
<Setter Property="Height" Value="35" />
<Setter Property="FontSize" Value="20" />
</Style>
[...]
<ComboBox SelectedIndex="{Binding Path=BirthdayDay, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Days, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox SelectedIndex="{Binding Path=BirthdayMonth, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Months, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox SelectedIndex="{Binding Path=BirthdayYear, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Years, UpdateSourceTrigger=PropertyChanged}" />
And the result is very confusing:
Is it somehow colliding with the TextBlock
Style
?
Since the FontWeight
is applied it seems like there is a connection ?!
NOTE:
The only "obvious" difference I can see it that the Binding differs:
Day + Year
is a Collection
of Integers
while Month
is a Collection
of string
?!
Upvotes: 3
Views: 67
Reputation: 2521
This is due to the type of the data and the fact that you didn't define a way to display the data : ItemTemplate, ItemTemplateSelector or StringFormat
If you add <Setter Property="ItemStringFormat" Value="{}{0}"></Setter>
All ComboBoxes will display correctly.
The ItemsControl.UpdateSelectionBoxItem is the function that is in charge of displaying data in the selection box but I couldn't figure how it treated int differently from String in the process of extracting and displaying the Item.
Anyway, int are displayed as TextBlocks and String as TextBox if I get it right, and that's why you int takes your Style.
Upvotes: 2
Reputation: 35
Maybe you could try something like this:
<Window.Resources>
<Style x:Key="CommonStyle" TargetType="FrameworkElement">
<Setter Property="Margin" Value="5" />
</Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource CommonStyle}">
</Style>
</Window.Resources>
Upvotes: -1