How To Use ValueConverter as StaticResource in Windows Phone 8
Asked Answered
S

1

9

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.

Sawdust answered 15/2, 2013 at 11:20 Comment(0)
T
17

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

public class TextColorConverter : IValueConverter

Temple answered 15/2, 2013 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.