如何在Windows Phone 8中将ValueConverter作为静态资源使用

9
以下是我的App.xaml文件:
<Application
    x:Class="SpinrWindowsMobile.App"
    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"
    >

    <!--Application Resources-->
    <Application.Resources >
        <ResourceDictionary>

            <local:LocalizedStrings xmlns:local="clr-namespace:SpinrWindowsMobile" x:Key="LocalizedStrings"/>
            <converter:TextColorConverter xmlns:converter="clr-namespace:SpinrWindowsMobile.Common" x:Key="TextColorConverter"></converter:TextColorConverter>

        </ResourceDictionary>
    </Application.Resources>

    ....
</Application>

我在 NameSpace SpinrWindowsMobile.Common 中编写了 TextColorConverter.cs 文件。但是启动应用程序时,出现了异常信息can not create Instance of Type SpinrWindowsMobile.Common.TextColorConverter ,我不知道自己哪里出了错。 以下是我的TextColorConverter.cs类。

class TextColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // some code
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
           // some code
        }
    }

我正在使用Microsoft Visual Studio 2012 For Windows Phone作为我的开发工具。 还有一件事我想分享,我在System.Windows.Data命名空间中找不到ValueConverstionAttribute类。 请问有人可以指导我错在哪里吗?
1个回答

17
你需要将你的类声明为公共类(默认情况下为内部类)。否则它无法被实例化。 public类TextColorConverter : IValueConverter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接