【问题标题】:How To Use ValueConverter as StaticResource in Windows Phone 8如何在 Windows Phone 8 中使用 ValueConverter 作为 StaticResource
【发布时间】:2023-03-18 11:43:01
【问题描述】:

下面是我的 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 SpinrWindowsMo​​bile.Common 中编写了 TextColorConverter.cs 启动应用程序时它给了我异常 can not create Instance of Type SpinrWindowsMo​​bile.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 Class。 谁能指导我哪里错了。

【问题讨论】:

    标签: c# xaml windows-phone-8 ivalueconverter valueconverter


    【解决方案1】:

    您将使您的课程成为公共课程(默认情况下它将是内部课程)。否则无法实例化。

    public 类 TextColorConverter : IValueConverter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多