Developer technologies | XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
<TextBox
Background="#FAFAD2"
Focusable="False"
HorizontalContentAlignment="Center"
Style="{StaticResource TextBoxKey}"
Text="{Binding Path=LastUpdate, Converter={StaticResource conDate}, StringFormat='MMMM d, yyyy'}" />
Here are the relevant parts of the converter:
Private LowerLimit As New Date(2019, 12, 31)
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsDate(value) Then
Dim val As Date = CDate(value)
Return If(val > LowerLimit, CStr(val), String.Empty)
Else
Return String.Empty
End If
End Function
And yet the displayed date is, for example, 9/1/2020
Why is the date not being displayed properly?
Try this converter:
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsDate(value) Then
Dim val As Date? = CDate(value)
Return If(val > LowerLimit, val, Nothing)
Else
Return Nothing
End If
End Function
StringFormat does not work if the value is a string, not date.
Alternatively, you can format the date (using val.ToString("MMMM d, yyyy")) inside the converter and return the formatted string.