VB.net命名空间和IvalueConverter错误
我知道以前有人问过这个问题,但我仍在尝试绕过iValueConverter和名称空间的概念,我正在努力学习 我指的是以下参考资料: 我的XAML代码:VB.net命名空间和IvalueConverter错误,vb.net,namespaces,ivalueconverter,Vb.net,Namespaces,Ivalueconverter,我知道以前有人问过这个问题,但我仍在尝试绕过iValueConverter和名称空间的概念,我正在努力学习 我指的是以下参考资料: 我的XAML代码: <Window x:Class="WpfTutorialSamples.DataBinding.ConverterSample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schema
<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>
我已阅读StackOverflow对原始海报问题的回复,并确保:
1) clr命名空间没有语法错误
2) 措辞WpfTutorialSamples.DataBinding在XAML和VB.net代码中是一致的。拼写和大小写完全相同
3) VB代码中命名空间的声明在YesNo类之外
但我仍然得到如下错误:
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.
我真的很困惑,为什么我会犯这些错误,因为我完全是照本宣科。如果有人能帮我一把,我将不胜感激。请想一想,在您的VB项目设置中,是否为根命名空间设置了值?如果是这样,您可以尝试删除该选项。VB将根命名空间添加为任何已声明命名空间的一部分,因此实际命名空间可能是
RootNamespaceName.WpfTutorialSamples.DataBinding
。我转到解决方案资源管理器并单击项目文件的属性。我找不到您引用的命名空间信息。我看错地方了吗?在项目属性中的“应用程序”选项卡上有一个“根命名空间”文本框。只需清除那个文本框,谢谢。我们现在已经这样做了。现在代码出现此错误-类型为“wpfutorialsamples.DataBinding.YesNoToBooleanConverter”的对象无法应用于类型为“System.Windows.Data.IValueConverter”的属性。有什么想法吗?我不确定,但看起来您已经在YesNo
类中实现了IValueConverter
。因此,在xaml中,您可能需要将x:Key=“YesNoToBooleanConverter”
更改为x:Key=“YesNo”
?
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.