2013-08-02 61 views
0

我新的WPF,我需要使用转换器..WPF转换错误

我有这个在我的vb.net代码转换器

Namespace converters 
<ValueConversion(GetType(Double), GetType(Double))> _ 
Public Class WidthConverter 
    Implements IValueConverter 

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert 
     ' value is the total width available 

     Dim otherWidth As Double 
     Try 
      otherWidth = System.Convert.ToDouble(parameter) 
     Catch 
      otherWidth = 100 
     End Try 
     If otherWidth < 0 Then 
      otherWidth = 0 
     End If 

     Dim width As Double = CDbl(value) - otherWidth 
     If width < 0 Then 
      width = 0 
     End If 
     Return width 
     ' columnsCount; 
    End Function 

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack 
     Throw New NotImplementedException() 
    End Function 
End Class 

末命名空间

在我的XAML我有这个

<Window x:Class="MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="clr-namespace:WPF_NewProject.converters"  
Title="MainWindow" Height="594.796" Width="596.221"> 

其中有没有错误,但是当我这样做

<Window.Resources> 
     <local:WidthConverter x:Key="widthConverter"/> 
</Window.Resources> 

我得到

“WidthConverter” 这个名字并不在命名空间中存在 “CLR的命名空间:WPF_NewProject.converters”。

所以我需要知道这是一个错误还是我做错了什么?

编辑

我也有同样的结果尝试这样做。

xmlns:local="clr-namespace:converters" 

编辑2

我只是做了一个新的空白项目,并尝试了完全一样的方式和它的作品..?

+0

尝试建设项目,并检查它是解决错误。 –

+0

我曾尝试过,仍然无法正常工作。 – Mattigins

+0

您可以先清理解决方案,在这种情况下建立它有时可以帮助.. – loop

回答

0

错误说The name "WidthConverter" does not exist in the namespace "clr-namespace:WPF_NewProject.converters".

您转换器的第一行说Namespace converters

要么改变你的声明命名空间WPF_NewProject.converters或者改变你的XML命名空间声明xmlns:local="clr-namespace:converters"

+0

正如第一次编辑所述,我已经这样做了。 – Mattigins