VB.net Namespace and IvalueConverter error

1.5k Views Asked by At

I know this has been asked before but I am still trying to get around the iValueConverter and Namespace concept and I am trying to learn.

I refer to the following references:

http://www.wpf-tutorial.com/data-binding/value-conversion-with-ivalueconverter/

The name "YesNo" does not exist in the namespace "clr-Namespace:WPF_Tutorial.WPFTutorials.Converter"

My XAML code:

<Window x:Class="WpfTutorialSamples.DataBinding.ConverterSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfTutorialSamples.DataBinding"
        Title="ConverterSample" Height="140" Width="250">
    <Window.Resources>
        <local:YesNoToBooleanConverter x:Key="YesNoToBooleanConverter" />
    </Window.Resources>
    <StackPanel Margin="10">
        <TextBox Name="txtValue" />
        <WrapPanel Margin="0,10">
            <TextBlock Text="Current value is: " />
            <TextBlock Text="{Binding ElementName=txtValue, Path=Text, Converter={StaticResource YesNoToBooleanConverter}}"></TextBlock>
        </WrapPanel>
        <CheckBox IsChecked="{Binding ElementName=txtValue, Path=Text, Converter={StaticResource YesNoToBooleanConverter}}" Content="Yes" />
    </StackPanel>
</Window>

My VB.net code

Imports System.Windows
Imports System.ComponentModel
Imports System.Windows.Data
Namespace WpfTutorialSamples.DataBinding
    Public Class YesNoToBooleanConverter
    End Class

    Public Class YesNo
        Implements IValueConverter

        Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
            Select Case value.ToString.ToLower
                Case "yes"
                    Return True
                Case "no"
                    Return False
            End Select
            Return False
        End Function

        Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
            If TypeOf value Is Boolean Then
                If CBool(value) = True Then : Return "yes"
                Else : Return "no"
                End If
            Else : Return "no"
            End If
        End Function
    End Class

End Namespace

I have read StackOverflow's responses to the original poster questions and I have ensure that:

1) There is no syntax error to the clr-namespace.

2) The wording WpfTutorialSamples.DataBinding is consistent in the XAML and VB.net code. Spelling and case is the exact same.

3) declaration of the namespace in the VB code is outside of the YesNo Class.

But I am still getting the errors as follows:

The name "YesNoToBooleanConverter" does not exist in the namespace "clr-namespace:WpfTutorialSamples.DataBinding".  

The tag 'YesNoToBooleanConverter' does not exist in XML namespace 'clr-namespace:WPFTutorials.Converter'. 

The type 'local:YesNoToBooleanConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'WpfTutorialSamples.DataBinding' that could not be found.    

I am really puzzled why am I getting these errors because I have done exactly by the book. If anyone could give me a hand that will be most appreciated.

0

There are 0 best solutions below