2013-02-15 38 views
9

下面是我的App.xaml如何在Windows手機上使用ValueConverter作爲StaticResource的8

<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> 

我在命名空間書面TextColorConverter.csSpinrWindowsMo​​bile.Common 雖然啓動應用程序這讓我異常無法創建類型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對於Windows Phone作爲我的開發工具。 我想分享的另一件事我沒有得到ValueConverstionAttribute類System.Windows.Data命名空間。 任何人都可以指導我,我錯在哪裏。

回答

17

您將使您的課程成爲公開課程(默認情況下它將成爲內部課程)。否則它不能被實例化。

公共類TextColorConverter:的IValueConverter

+1

感謝paul.You救了我寶貴的工作時間。 – 2013-02-18 07:29:54