2014-07-08 207 views
-1

大家好(我和这是我第一次在这里发帖)我一直在努力解决这个问题一段时间,我一直在看样本和教程,仍然在失利。我仍然试图让自己的脚在WPF世界中变得湿润,并且只是抓表面,因此是一个非常简单的例子。我在这里读过几个人问同样的问题,但我没有看到我的例子中的相同问题,并且该决议似乎没有关系。我很抱歉问了一些已经问过的问题。WPF命名空间标记xxx不存在于XML命名空间

非常感谢你提前为任何输入

我有在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:BooleanToVisibilityConverter'。验证您是否缺少程序集引用,并且所有引用的程序集都已构建。

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

回答

0

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

而且Window.resources在你的键名是“转换器”,当您使用“boolToVis”的标贴标签,你可以做的是在XAML中移除转换器使用的建设项目后,

还有一两件事,写入xmlns:l =。您的完整程序集名称将显示在列表中。这样可以避免写入不正确的装配路径。

+0

我没有按照建议删除转换器...只是提供完整的组装路径似乎工作。谢谢你,并为这个愚蠢的问题感到抱歉。 – user3814606

相关问题