XML命名空间中不存在WPF命名空间标签xxx



我在vb中有以下内容:

Namespace WpfSample
Class MainWindow
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub
End Class

Public Class BooleanToVisibilityConverter
    Implements IValueConverter
    Public Sub New()
    End Sub
    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value.Equals(True) Then
            Return System.Windows.Visibility.Visible
        Else
            Return System.Windows.Visibility.Collapsed
        End If
    End Function
    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        If value.Equals(System.Windows.Visibility.Visible) Then
            Return True
        Else
            Return False
        End If
    End Function
End Class
End Namespace

那么我的XAML看起来像:

<Window x:Class="WpfSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:WpfSample"
    Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
    <l:BooleanToVisibilityConverter x:Key="converter" />
    </Window.Resources>
    <Grid>
        <TextBox x:Name="txtName" HorizontalAlignment="Left" Height="23" Margin="112,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label x:Name="lblLabel" Content="{Binding Text, ElementName=txtName,UpdateSourceTrigger=PropertyChanged}" 
           Visibility="{Binding IsChecked,ElementName=chkShowLabel, Converter={StaticResource boolToVis}}"
           HorizontalAlignment="Left" Margin="256,37,0,0" VerticalAlignment="Top"/>
        <CheckBox x:Name="chkShowLabel" Content="Show Label" HorizontalAlignment="Left" Margin="112,65,0,0" VerticalAlignment="Top"/>
    </Grid>
</Window>

我看到以下3个错误命名空间clr-namespace:WpfSample中不存在BooleanToVisibilityConverter。

找不到类型'l: boolean可见度转换器'。确认没有遗漏程序集引用,并且所有引用的程序集都已生成。

标签'BooleanToVisibilityConverter'在XML命名空间'clr-namespace:WpfSample'中不存在。

从示例中删除转换器的使用,并首先构建您的项目。只有在它构建成功之后,你才能在xaml中使用它。

也是窗口下的键名。当您在标签标签

中使用"boolToVis"时,资源为"converter"。

您可以做的另一件事是在通过删除xaml中的转换器使用构建项目后,编写xmlns:l=。您的完整程序集名称将显示在列表中。这样可以避免编写错误的程序集路径。

最新更新