簡體   English   中英

WPF日歷顯示很多個月

[英]Wpf calendar show many months

我需要在同一日歷中同時顯示至少兩個月(secure),但無法使用WPF的calentdar控件執行此操作。

我怎樣才能做到這一點 ?

為什么不添加兩個日歷,並使用以下轉換器和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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM