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.
MyWin.XAML:
<Window x:Class="MyWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyWin" Height="300" Width="300"
xmlns:local="clr-namespace:MyNameSpace">
<Window.Resources>
<local:DateConvertor x:Key="MyDateConverter"/>
</Window.Resources>
<Grid>
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Width="auto" Header="Do By">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="4" Text="{Binding Path=DoByDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Path=DoByDate, Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
MyWin.XAML.VB:
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()
InitializeComponent()
End Sub
End Class