簡體   English   中英

如何更改 WPF DatePicker 的顯示數據格式

[英]How to change the display data format of the WPF DatePicker

我從這個論壇得到了這個示例代碼。

<DatePicker SelectedDate="{Binding MainReportEndDate, Mode=TwoWay}"
                            DataContext="{Binding DataContext, RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}}" 
                            
                            DisplayDateStart="1/01/20" DisplayDateEnd="12/31/22"
                            FirstDayOfWeek="Monday"">
        <DatePicker.Resources>
            <Style TargetType="{x:Type DatePickerTextBox}">
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBox x:Name="PART_TextBox"
                                     Text="{Binding Path=SelectedDate, 
                                            RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}, 
                                            StringFormat={}{0:MMM yy}}" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </DatePicker.Resources>
    </DatePicker>

但它不起作用。 我想要與圖片“7 月 20 日”中的結果相同的結果

在此處輸入圖像描述

嘗試這個

<TextBox x:Name="PART_TextBox"
     Text="{Binding Path=SelectedDate, StringFormat='dd MMM yyyy', 
     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />

暫無
暫無

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

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