Jay Jay - 8 months ago 34
Vb.net Question

WPF Designer Binding with Converter throwing Object Reference not set to instance of an object

My XAML designer shows Object reference not set to instance errors everywhere I'm using one of my converter while binding. After digging a lot I've found that it happens at this particular line because it is not able to find get the value at design time.


Even when i try to avoid it by checking it is not null, it still throws the object reference error

TransactionViewModel is a singleton class with 'getInstance()' function to get the instance.

This is my convert function as follows

Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
Dim FieldName As String = value.ToString
Dim FieldNum As Integer = Integer.Parse(parameter)

If TransactionViewModel.getInstance IsNot Nothing Then
If TransactionViewModel.getInstance._NR IsNot Nothing Then
If TransactionViewModel.getInstance._NR.ContainsField(FieldNum, FieldName) Then
Return Visibility.Visible
Return Visibility.Hidden
End If
End If
End If
Return Visibility.Visible
End Function

Any suggestions?


Please try with this it may help you

if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
    //Code that throws the exception
   //Code that return null


If Not System.ComponentModel.DesignerProperties.GetIsInDesignMode(New DependencyObject) Then
        'Code that throws the ex
        'Code that return null
End If