加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在Windows Phone 8中使用ValueConverter作为StaticRes

发布时间:2020-12-15 06:48:46 所属栏目:百科 来源:网络整理
导读:以下是我的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;as
以下是我的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
在启动应用程序时它给我异常无法创建类型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,System.Globalization.CultureInfo culture)
        {
           // some code
        }
    }

我正在使用Microsoft Visual Studio 2012 Windows Phone作为我的开发工具.
还有一件事我想分享我没有在System.Windows.Data命名空间中获取ValueConverstionAttribute类.
任何人都可以指导我错在哪里.

解决方法

您将使您的课程成为一个公共课程(默认情况下,它将是内部的).否则不能实例化.

public class TextColorConverter:IValueConverter

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读