Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
名称为;是的,没有;命名空间中不存在“0”;clr名称空间:WPF_Tutorial.WPFTutorials.Converter“;_Wpf_Vb.net_Namespaces_Converters - Fatal编程技术网

名称为;是的,没有;命名空间中不存在“0”;clr名称空间:WPF_Tutorial.WPFTutorials.Converter“;

名称为;是的,没有;命名空间中不存在“0”;clr名称空间:WPF_Tutorial.WPFTutorials.Converter“;,wpf,vb.net,namespaces,converters,Wpf,Vb.net,Namespaces,Converters,我正在努力学习WPF 我在WPF和VB.Net中遇到转换问题。我用的是VS2012 这是我的XML代码 <Window x:Class="Binding_Sample_Converter" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-Namespace:WPF_

我正在努力学习WPF

我在WPF和VB.Net中遇到转换问题。我用的是VS2012

这是我的XML代码

<Window x:Class="Binding_Sample_Converter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-Namespace:WPF_Tutorial.WPFTutorials.Converter"  
Title="Binding_Sample_Converter" Height="300" Width="300">
<Window.Resources>
    <!--
    Error   1   The name "YesNo" does not exist in the namespace "clr-Namespace:WPF_Tutorial.WPFTutorials.Converter".
    Error   2   The name "YesNo" does not exist in the namespace "clr-Namespace:WPF_Tutorial.WPFTutorials.Converter".
    Error   3   The type 'local:YesNo' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

    -->
    <local:YesNo x:Key="YesNo" />
</Window.Resources>
<Grid>

</Grid>
我正在尝试将上述网站教程中的C代码转换为VB.Net

错误是

        Error   1   The name "YesNo" does not exist in the namespace "clr-Namespace:WPF_Tutorial.WPFTutorials.Converter".
    Error   2   The name "YesNo" does not exist in the namespace "clr-Namespace:WPF_Tutorial.WPFTutorials.Converter".
    Error   3   The type 'local:YesNo' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
请帮忙

提前谢谢

阿米特·萨拉夫

编辑。 呃,修改后的警告

        <!--
    Warning 1   Namespace or type specified in the Imports 'WPFTutorials.Converter' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  D:\Data - 2012\WPF\WPF_Tutotrial\obj\Debug\Binding_Sample_Converter.g.i.vb  35  9   WPF_Tutotrial
    Error   2   The name "YesNo" does not exist in the namespace "clr-namespace:WPFTutorials.Converter".    D:\Data - 2012\WPF\WPF_Tutotrial\Binding_Sample_Converter.xaml  11  9   WPF_Tutotrial
    Error   3   The type 'local:YesNo' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. D:\Data - 2012\WPF\WPF_Tutotrial\Binding_Sample_Converter.xaml  12  10  WPF_Tutotrial
    -->

您的代码中有两个问题

首先,命名空间名称区分大小写<代码>N应为小写。命名空间声明的语法为
clr namespace

Second
yesn在
Binding\u Sample\u Converter
的嵌套类中没有类,它不应该是。您不能在XAML中创建嵌套类的实例。发件人:

为了能够被实例化为对象元素,您的 类必须满足以下要求:

  • 您的自定义类必须 必须是公共的,并支持默认(无参数)公共构造函数

  • 你的习惯 类不能是嵌套类。嵌套类和中的“点” 它们的通用CLR使用语法会干扰其他WPF和/或XAML 附加特性等功能

  • XAML:

    转换器:

    YesNo
    类移出类
    Public class Binding\u Sample\u Converter
    并直接在名称空间下声明它

    Namespace WPFTutorials.Converter
       Public Class Binding_Sample_Converter
       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
    

    按照您的说明进行了更改,但错误仍然存在。现在出现了新的警告,即“代码”警告:导入“WPFTutorials.Converter”中指定的命名空间或类型不包含任何公共成员,或者找不到。确保已定义命名空间或类型,并且至少包含一个公共成员。确保导入的元素名称不使用任何别名。是否已将
    YesNo
    类声明移到类
    Binding\u Sample\u Converter
    之外?是的,这是代码命名空间WPFTutorials。Converter公共类YesNo实现IValueConverter…代码移到此处End class End Namespace完成此操作,但还是犯了很多错误。再见。
    xmlns:local="clr-namespace:WPFTutorials.Converter"
    
    Namespace WPFTutorials.Converter
       Public Class Binding_Sample_Converter
       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