VB.net命名空间和IvalueConverter错误

时间:2017-01-08 08:03:24

标签: vb.net namespaces ivalueconverter

我知道之前已经问过这个问题,但我仍然试图绕过iValueConverter和Namespace概念,我正在努力学习。

我参考以下参考文献:

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"

我的XAML代码:

<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>

我的VB.net代码

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

我已阅读StackOverflow对原始海报问题的回复,并确保:

1)clr-namespace没有语法错误。

2)WpfTutorialSamples.DataBinding的措辞在XAML和VB.net代码中是一致的。拼写和案例完全相同。

3)VB代码中的命名空间声明在YesNo Class之外。

但我仍然得到如下错误:

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.    

我真的很困惑为什么我会收到这些错误,因为我完全按照这本书做了。如果有人能给我一个最受欢迎的手。

0 个答案:

没有答案