RadCombobox 属性 在 GotFocus 和 LostFocus 之间失去价值

RadCombobox property losing value between GotFocus and LostFocus

我有一个 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有什么需要设置的?

感谢您的帮助或建议。

尝试将 ComboBoxSelectedValuePath 设置为 "WoodSpecies" 并绑定 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}" >