[英]DateTime ToString Converter C# to vb.net
我將這段代碼從下面的代碼轉換為VB.net
public class DateTimeToStringConverter: IValueConverter
{
public object Convert(object value, Type type, object parameter, string language)
{
string result = "";
if (value is DateTime)
{
DateTime theDate = (DateTime)value;
result = string.Format("{0:d}", theDate);
}
else
{
DateTime theDate = DateTime.Now;
result = string.Format("{0:d}", theDate);
}
return result;
}
public object ConvertBack(object value, Type type, object parameter, string language)
{
return System.Convert.ToDateTime(value);
}
}
轉換后的代碼
我收到錯誤2, “ DateTimeToStringConverter”必須為接口“ Windows.UI.Xaml.Data.IValueConverter”實現“函數Convert(值作為對象,targetType作為System.Type,參數作為對象,語言作為字符串)作為對象”
Public Function Convert(ByVal value As Object, ByVal type As Type, ByVal parameter As Object, ByVal language As String) As Object
Dim result As String = ""
If TypeOf value Is Date Then
Dim theDate As Date = DirectCast(value, Date)
result = String.Format("{0:d}", theDate)
Else
Dim theDate As Date = Date.Now
result = String.Format("{0:d}", theDate)
End If
Return result
End Function
Public Function ConvertBack(ByVal value As Object, ByVal type As Type, ByVal parameter As Object, ByVal language As String) As Object
Return System.Convert.ToDateTime(value)
End Function
任何人都可以在這里幫助我,在此先感謝,謝謝
解決方案很可能是implements
關鍵字。以這種方式更改代碼:
Public Function Convert(ByVal value As Object, ByVal type As Type, ByVal parameter As Object, ByVal language As String) As Object implements IValueConverter.Convert
Dim result As String = ""
If TypeOf value Is Date Then
Dim theDate As Date = DirectCast(value, Date)
result = String.Format("{0:d}", theDate)
Else
Dim theDate As Date = Date.Now
result = String.Format("{0:d}", theDate)
End If
Return result
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.