Click here to Skip to main content
15,606,657 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Would appreciate help to get this code to work.

I'm using VisualStudio 2012, using WPF with VB.NET.

I have a namespace named MyNameSpace. It's defined at the solution level

It has a number of projects within it.

I'm trying to get a ValueConverter to be recognized so that I can use it.

Purpose is to convert a value of type DateTime, which includes date and time, to simply MM/dd/yyyy

Below is code for a window in one project, followed by the window's code-behind.

Thank you very much.


<Window x:Class="MyWin"
    Title="MyWin" Height="300" Width="300"
        <!-- ERROR ON NEXT LINE: The name DateConverter does not exist in the namespace-->
        <local:DateConvertor x:Key="MyDateConverter"/>
                <DataGridTemplateColumn  Width="auto" Header="Do By">
                            <TextBlock Margin="4" Text="{Binding Path=DoByDate}" />
                            <!-- Cannot use the converter to show MM/dd/yyyy.-->
<!--                        <TextBlock Margin="4" Text="{Binding Path=DoByDate, Converter={StaticResource DateConvertor}}" /> -->
                            <DatePicker SelectedDate="{Binding Path=DoByDate, Mode=TwoWay}" />


Imports System.Globalization
Public Class MyWin
    Public Class DateConvertor
        Implements IValueConverter
        Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
            Return DirectCast(value, DateTime).ToString("MM/dd/yyyy")
        End Function
        Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
            Return DateTime.ParseExact(value.ToString(), "ddMMyyyy", CultureInfo.InvariantCulture)
        End Function
    End Class
    Public Sub New()
        ' This call is required by the designer.
        ' Add any initialization after the InitializeComponent() call.
    End Sub
End Class
Updated 16-Aug-13 9:26am

If it is in another assembly, then you have to add the assembly informaton. i.e.:

Share this answer
Member 10191023 16-Aug-13 16:40pm    
It's in the same assembly.
Clifford Nelson 16-Aug-13 16:48pm    
So why do you point out you have multiple projects. If this is all in the same project... What is in the other projects?
what is LSE, if you write that you use namespace MyNameSpace? Use MyNameSpace instead of LSE
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900