wpf - RadCombobox 属性在 GotFocus 和 LostFocus 之间失去值(value)

标签 wpf telerik radcombobox

我有一个 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”并绑定(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/

相关文章:

Javascript,如何利用占位符内动态创建的 RadGrid 中的 get_masterTableView

wpf - 需要帮助在 Telerik RadControls 和 DevExpress DXperience (WPF) 之间做出决定

asp.net - 仅下面的 RadComboBox 下拉菜单

c# - WPF C# 将标签绑定(bind)到包含自定义对象的 ObervableCollection 的 DataGrid

wpf - 用于添加新实体的 MVVM WPF ViewModels

javascript - 如何从radupload获取文件的真实路径

css - 更改 RadComboBox 的颜色

c# - Mysql WHERE LIKE 与 RadCombobox.Text

c# - 从 ViewModel 了解数据绑定(bind)

c# - 获取 wpf 组合框选择的值