locked
IValueConverter correctly declared but not working

    Question

  • After I recreated and rebuilt an app based on my old app, I have this error that did not happen in my old app.


    The problem on stringFormatConverter

    Error message:

     The name stringFormatConverter does not exist in the namespace MobileSalesSystem

     


    -- here my page:
    <common:LayoutAwarePage

    xmlns:local="using:MobileSalesSystem"
    xmlns:c="using:MobileSalesSystem"


    xmlns:common="using:MobileSalesSystem.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

     <Page.Resources>           
               
      <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
               
      <x:String x:Key="AppName">My Application</x:String>
               
      <c:stringFormatConverter x:Key="StringFormatConverter"></c:stringFormatConverter>  <-- error here

      // same error if use :

     <local:stringFormatConverter  x:Key="StringFormatConverter"/>

     </Page.Resources>


    .......

     <TextBlock Margin="40,0,0,0" FontSize="23" Foreground="DarkBlue" TextAlignment="Right" Text="{Binding SalesDate,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0:dd MMM yyyy}'}" TextWrapping="Wrap"  Grid.Row="0" Grid.Column="7" />

     


    but I have this class as below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.UI.Xaml.Data;

    namespace MobileSalesSystem
    {
        class stringFormatConverter : IValueConverter
        {

            public object Convert(object value, Type targetType, object parameter, string language)
            {         
                DateTime dt = (DateTime)value;
                string arg = dt.ToString("d");         
                return arg;
            }


            public object ConvertBack(object value, Type targetType, object parameter, string language)
            {
                return value;
            }     

        }
    }

    Tuesday, March 11, 2014 2:56 PM

Answers

  • Try restarting VS and see if it helps. I've had to do that several times.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by FireDance Wednesday, March 12, 2014 2:55 AM
    Tuesday, March 11, 2014 3:34 PM
    Moderator
  • Finally, to make it work again.

    I have to delete

    1)

       <TextBlock Margin="40,0,0,0" FontSize="23" Foreground="DarkBlue" TextAlignment="Left" Text="{Binding Order_Date,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0:dd MMM yyyy}'}" TextWrapping="Wrap"  Grid.Row="0" Grid.Column="5" />

    2) the Binding Control

    and build and recreate again.

    Thanks

    Wednesday, March 12, 2014 2:57 AM

All replies

  • Try restarting VS and see if it helps. I've had to do that several times.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by FireDance Wednesday, March 12, 2014 2:55 AM
    Tuesday, March 11, 2014 3:34 PM
    Moderator
  • Finally, to make it work again.

    I have to delete

    1)

       <TextBlock Margin="40,0,0,0" FontSize="23" Foreground="DarkBlue" TextAlignment="Left" Text="{Binding Order_Date,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0:dd MMM yyyy}'}" TextWrapping="Wrap"  Grid.Row="0" Grid.Column="5" />

    2) the Binding Control

    and build and recreate again.

    Thanks

    Wednesday, March 12, 2014 2:57 AM