Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use ValueConverter as StaticResource in Windows Phone 8

Below is my 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>

I had written TextColorConverter.cs in NameSpace SpinrWindowsMobile.Common While launching the app It gives me exception can not create Instance of Type SpinrWindowsMobile.Common.TextColorConverter . I don't know where am I missing. Below is the my TextColorConverter.cs class

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

I am using Microsoft Visual Studio 2012 For Windows Phone as My Development Tool. One more thing I want to share I am not getting ValueConverstionAttribute Class in System.Windows.Data namespace. Can anyone guide me where am I wrong.

like image 679
Ashwin N Bhanushali Avatar asked Feb 15 '13 11:02

Ashwin N Bhanushali


1 Answers

You will make your class a public class (by default it will be internal). Otherwise it can't be instantiated.

public class TextColorConverter : IValueConverter

like image 157
Paul Annetts Avatar answered Oct 22 '22 14:10

Paul Annetts