Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8.1 - Converters do not work using platform target ARM

I've developed app on windows phone 8.1. Several of my pages have the custom converter; for example:

 using System;
 using System.Globalization;
 using Windows.UI.Xaml.Data;

 namespace XXXXX.Model.Converters
 {
     public sealed class DateTimeToStringConverter : IValueConverter
     {
         public object Convert(object value, Type targetType, object parameter, string language)
         {
             var date = (DateTime)value;

             return date.ToString("g", new CultureInfo("it-IT"));
         }

         public object ConvertBack(object value, Type targetType, object parameter, string language)
         {
             throw new NotImplementedException();
         }
     }
 }

In the XAML i have:

 <Page
     x:Class="XXXXX.Views.VehiclesView"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:converters="using:XXXXX.Model.Converters"
     mc:Ignorable="d"
     FontFamily="{StaticResource PhoneFontFamilyNormal}"
     Foreground="{StaticResource PhoneForegroundBrush}">

     <Page.Resources>
         <converters:DateTimeToStringConverter x:Key="DateTimeToStringConverter" />
         <converters:StringFormatConverter x:Key="StringFormatConverter" />
     </Page.Resources>

And use it in this way:

 <TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding Distance, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0} Km'}"></TextBlock>

1) Why does the compiler gives me this error?

 The name "DateTimeToStringConverter" does not exist in the namespace using:XXXXX.Model.Converters

2) Why does it work if I change the target platform to x86?

3) If I wanted to work in XAML and not in Code Behind, are there alternatives to the Converter?

like image 697
Fra Avatar asked Oct 01 '22 06:10

Fra


1 Answers

Try to move converters in dedicate class library with target platform "AnyCPU", and reference it in your application project.

like image 195
Max Avatar answered Oct 03 '22 04:10

Max