0

IValueConverter クラスを実装し、xaml ファイルのリソースとしてマップしようとしています。何らかの理由で、常に「名前 TypeConverter が名前空間 clr-namespace:MyApp に存在しません」というエラーが表示されます。

しかし、そこに何が問題なのかがわかりません。私のコンバータークラスには名前空間が正しく設定されています..

私の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;
        }
    }
}
4

1 に答える 1

0

自分で問題を見つけました。convert メソッドには間違ったパラメーターがあり、次のようにする必要があります。

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

これを修正すると、コンパイラ (および) デザイナは名前空間エラーを出さなくなりました。

于 2013-07-14T12:53:13.173 に答える