'Combobox text is getting cleared on clicking outside of combobox in WPF application
I have defined a combobox inside a DataGrid. below is the xaml code:
<DataGridTemplateColumn Width="2*" Header="Modality">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name ="CmbModality" UseLayoutRounding="True" FontFamily="
{StaticResource SiemensSansFontFamily}" FontSize="15" FontWeight="Regular"
Style="{StaticResource InputDataOrderGridComboBoxStyle}"
Margin="10 15 10 15" Foreground="{StaticResource WhiteOpacityNinetyPercentage}"
VerticalAlignment="Top" Height="30"
Text="{Binding Modality, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="CmbModality_SelectionChanged"
PreviewMouseLeftButtonDown="CmbModality_PreviewMouseLeftButtonDown">
<ComboBoxItem>NM</ComboBoxItem>
<ComboBoxItem>PT</ComboBoxItem>
<ComboBoxItem>CT</ComboBoxItem>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Data grid binding is done to an observable collection and combo box is populated as expected but whenever I click outside of combo box(area just about it), Combo box text get cleared and when I double click again It appears back. Don't know why this is happening. Any help is much appreciated.
please see pic( dots in the pic shows where I click and combobox gets cleared). https://i.stack.imgur.com/Ci4fh.png
Solution 1:[1]
There are some possibilities.
You have a binding to a property named Modality. Is this property placed in a view model? Your UI can get a null from the origin because of the "TwoWay" binding.
Then you have something defined for the SelectionChanged. What does this method do?
Third point is the style. What is in InputDataOrderGridComboBoxStyle defined? Some triggers can also impact your selection.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
