0

I got this sample code from this forum.

<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>

But it doesn't work. I want the same result as the one in the picture "Jul 20"

enter image description here

Masoud Keshavarz
  • 2,166
  • 9
  • 36
  • 48

1 Answers1

0

Try this

<TextBox x:Name="PART_TextBox"
     Text="{Binding Path=SelectedDate, StringFormat='dd MMM yyyy', 
     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
Albin C S
  • 340
  • 1
  • 5