我需要在同一个日历中同时显示至少两个月(secuential),但无法使用WPF的日历控件来执行此操作。
我该怎么做?
答案 0 :(得分:0)
为什么不添加两个日历,双向将第二个的displaydate绑定到第一个的displaydate,使用以下转换器,将1作为ConverterParameter)
Public Class AddMonthConverter
Implements Windows.Data.IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Return addMonths(value, targetType, parameter, True)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return addMonths(value, targetType, parameter, False)
End Function
Private Function addMonths(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal isIncrease As Boolean) As Object
If Not (targetType Is GetType(DateTime?) OrElse targetType Is GetType(DateTime)) Then
Throw New InvalidOperationException("The target and value must be a DateTime?")
Else
Dim dteValue As DateTime? = CType(value, DateTime?)
Dim intMonthsToAdd As Int32
If parameter Is Nothing OrElse Int32.TryParse(parameter.ToString, intMonthsToAdd) = False Then
intMonthsToAdd = -1
End If
If dteValue.HasValue Then
If isIncrease Then
Return dteValue.Value.AddMonths(intMonthsToAdd)
Else
Return dteValue.Value.AddMonths(-intMonthsToAdd)
End If
Else
Return dteValue
End If
End If
End Function
End Class