我有一个 radcombobox,其属性在 GotFocus 和 LostFocus 事件之间的某个位置失去了值。
XAML:
<telerik:RadComboBox x:Name="cboWoodSpecies"
FontSize="16" Margin="0,4,0,0" Background="#F6F8FA" BorderBrush="#D7D8DD"
ItemsSource="{Binding}" Text="{Binding woodSpecies, Mode=TwoWay}"
telerik:TextSearch.TextPath="WoodSpecies"
IsEditable="True" IsReadOnly="True" TabIndex="0"
Style="{DynamicResource RadComboBoxStyle3}" >
GotFocus 事件:
Private Sub cboWoodSpecies_GotFocus(sender As Object, e As RoutedEventArgs) Handles cboWoodSpecies.GotFocus
BindComboBoxes.WoodSpecies(cboWoodSpecies) 'bind cbo to data
If thisOrder.woodSpecies <> String.Empty Then 'Property OK here!!
DisplayWoodSpeciesImage()
End If
End Sub
DisplayWoodSpeciesImage 读取属性值,但不会将其重置为 Nothing。
失去焦点:
Private Sub cboWoodSpecies_LostFocus(sender As Object, e As RoutedEventArgs) Handles cboWoodSpecies.LostFocus
If thisOrder.woodSpecies <> String.Empty Then 'Property = Nothing. Why?!?!
'do stuff
End If
End Sub
我认为这与组合框本身有关。从组合中选择新项目不会导致问题。正是用现有数据填充组合才导致问题。我必须重新选择该项目才能绕过该错误。
话虽这么说,有没有办法刷新组合框,以便它认为该项目已被再次选择?是不是SelectedItem需要设置什么东西?
感谢您的帮助或建议。
最佳答案
尝试将ComboBox
的SelectedValuePath
设置为“WoodSpecies”并绑定(bind)SelectedValue
(而不是Text
属性)到“woodSpecies”:
<telerik:RadComboBox x:Name="cboWoodSpecies"
FontSize="16" Margin="0,4,0,0" Background="#F6F8FA" BorderBrush="#D7D8DD"
ItemsSource="{Binding}"
SelectedValuePath="WoodSpecies"
SelectedValue="{Binding woodSpecies, Mode=TwoWay}"
telerik:TextSearch.TextPath="WoodSpecies"
IsEditable="True" IsReadOnly="True" TabIndex="0"
Style="{DynamicResource RadComboBoxStyle3}" >
关于wpf - RadCombobox 属性在 GotFocus 和 LostFocus 之间失去值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42285315/