WPF: Mystery bug: Hunt, fix, but still not understand why
I got a bug report from client for a WPF application. Please look at the picture below:
The expected dropdown values are: I , unique II, III, IV, V
But it displayed “II” instead of “III”. I then check the value from data source. The data was correct. I then brought up my Visual Studio and ran the app. No, issue found.
After some discussion, I then tried with Windows 7, and Windows 8. And after some tries with changing the value for “III” item. The conclusions are:
- It works fine with Windows Server 2008 R2.
- It does not work on Windows 7 and Windows 8
- Only happen if “III” stands alone. If you add space (“I II”), it works
After hunting down the code, I ended up at the template to display the combo box item ( I need to use custom template for my own purpose)
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" Height="35" Padding="5"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
Accidentally, I changed Padding from “5” to “3” ( I love number “3”). To my all surprise, it worked . I then tried with number “4”. It did not.
It will work with value less than or equal 3.
But I still do not understand the reason Just post it here if someone can explain to me or if someone has the same problem might find the answer.