2013-07-14 57 views
0

我嘗試實現IValueConverter類並將其映射爲xaml文件中的資源。在某種原因,即時獲得永諾錯誤「的名稱類型轉換器不會在命名CLR的命名空間中:MyApp的」IValueConverter資源,命名空間問題

但我找不到什麼問題出現,我的轉換器類已命名空間設定正確等。

我的XML文件

<phone:PhoneApplicationPage 
    x:Class="MyApp.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:MyApp" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    mc:Ignorable="d" 
    shell:SystemTray.IsVisible="True"> 

... 

<ListBox ItemsSource="{Binding items}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 

    <ListBox.Resources> 
     <local:TypeConverter x:Name="TypeConverter"/> 
    </ListBox.Resources> 

    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 

    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding type, Converter={StaticResource TypeConverter}}" Margin="0,0,12,0" /> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 

</ListBox> 

我的轉換器類

namespace MyApp 
{ 
    public class TypeConverter: IValueConverter 
    { 

     public object Convert(object value, Type targetType, object parameter, String culture) 
     { 
      return "-"; 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, String culture) 
     { 
      return null; 
     } 
    } 
} 
+0

錯誤出現在設計器或編譯時? –

回答

0

發現問題我自己,轉換方法有錯誤的參數,需要是:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 

修復此問題時,編譯器(和)設計器不再提供命名空間錯誤。