I have this datepicker element:
<DatePicker
Name="DataSelected"
Grid.Column="1" Grid.Row="2"
SelectedDate="{Binding DataSelected, Mode=TwoWay}"
CalendarOpened="DatePicker_Opened">
<DatePicker.Resources>
<Style TargetType="DatePickerTextBox">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<TextBox x:Name="PART_TextBox"
Text="{Binding Path=SelectedDate,
RelativeSource={RelativeSource AncestorType={x:Type DatePicker}},
StringFormat={x:Static local:MyView.DateFormat}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DatePicker.Resources>
</DatePicker>
Now based on the value of the DateFormat variable which can be "yyyy" or "MM-yyyy" or "dd-MM-yyyy" I want to change the format of the datepicker. Because I want the user to able to select/see only the year if DateFormat is 'yyyy' or year and month if the variable is "MM-yyyy" and so on. How can I do that? (My code is in C#) (I am sorry for any grammatical errors, English is not my first language)