从ddMM自动获取完整日期dd / mm / YYYY

问题描述 投票:0回答:1

我们的日期格式为DD / MM / YYYY。如果用户仅输入日期和月份,则该应用应自动获取当前年份。例如:如果用户放置0104,则该应用应获取01/04/2020。需要根据日期自动获得年份

如果用户在DatePicker ddmm(ex.0401)上选择Date,则应当自动以dd / mm / yyyy格式(例如ex.04 / 01/2020)获得Date]

<DatePicker
            Grid.Column="3"
            x:Name="FinancialYear"
            HorizontalAlignment="Left" 
            Margin="74,317,0,0"
            VerticalAlignment="Top"
            SelectedDate="{Binding FinancialYear,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat='dd/MM/yyyy',ValidatesOnDataErrors=False}"
            Uid="none" Width="151"
            PreviewKeyDown="FinancialYear_PreviewKeyDown">
</DatePicker>
wpf xamarin mvvm wpf-controls mvvm-light
1个回答
0
投票
<DatePicker x:Name="FinancialYear"> <DatePicker.Resources> <Style TargetType="{x:Type DatePickerTextBox}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <TextBox x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, StringFormat='dd MM', RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </DatePicker.Resources> </DatePicker>
© www.soinside.com 2019 - 2024. All rights reserved.