Combobox和IDataErrorInfo

时间:2015-06-09 08:12:03

标签: wpf vb.net mvvm combobox idataerrorinfo

这是我的问题。 当我从组合框中选择一个项目时,(组合框已填充)我总是红色轮廓。

为什么?

<ComboBox x:Name="Cmb_USER" 
          TabIndex="5" 
          ItemsSource="{Binding User_USER, 
          ValidatesOnExceptions=True,
          ValidatesOnDataErrors=True,NotifyOnValidationError=True}" 
          IsEditable="True"      
          DisplayMemberPath ="DescUser" 
          Text="{Binding Path=USER}" Margin="114,105,98,179"/>
    Public Property User_USER As ObservableCollection(Of Model_User)
Private p_USER As String
Public Property USER() As String
    Get
        Return p_USER
    End Get
    Set(ByVal value As String)
        p_USER = value
        OnPropertyChanged("USER")
    End Set
End Property
#Region "IDataErrorInfo Members"
Public ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error
    Get
        Return Nothing
    End Get
End Property
Default Public ReadOnly Property Item(ByVal Name As String) As String Implements System.ComponentModel.IDataErrorInfo.Item
    Get
        Dim result As String = Nothing

        Select Case Name
            Case "User_USER"
                If USER = "" Then
                    result = "ERROR"
                End If
        End Select
        Return result
    End Get
End Property
#End Region

1 个答案:

答案 0 :(得分:0)

解决..  这是解决方案

Public Property USER() As String
Get
    Return p_USER
End Get
Set(ByVal value As String)
    p_USER = value
    OnPropertyChanged("USER")
    OnPropertyChanged("User_USER")
End Set

结束财产