दुर्भाग्यवश, अगर आप XAML के बारे में बात कर रहे हैं, तो आप SelectedDateFormat स्थापित करने के साथ फंस रहे हैं करने के लिए "लंबे समय" या "कम"।
यदि आपने टूलकिट के स्रोत को बाइनरी के साथ डाउनलोड किया है, तो आप देख सकते हैं कि यह कैसे परिभाषित किया गया है।
DatePicker.cs
#region SelectedDateFormat
/// <summary>
/// Gets or sets the format that is used to display the selected date.
/// </summary>
public DatePickerFormat SelectedDateFormat
{
get { return (DatePickerFormat)GetValue(SelectedDateFormatProperty); }
set { SetValue(SelectedDateFormatProperty, value); }
}
/// <summary>
/// Identifies the SelectedDateFormat dependency property.
/// </summary>
public static readonly DependencyProperty SelectedDateFormatProperty =
DependencyProperty.Register(
"SelectedDateFormat",
typeof(DatePickerFormat),
typeof(DatePicker),
new FrameworkPropertyMetadata(OnSelectedDateFormatChanged),
IsValidSelectedDateFormat);
/// <summary>
/// SelectedDateFormatProperty property changed handler.
/// </summary>
/// <param name="d">DatePicker that changed its SelectedDateFormat.</param>
/// <param name="e">DependencyPropertyChangedEventArgs.</param>
private static void OnSelectedDateFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
DatePicker dp = d as DatePicker;
Debug.Assert(dp != null);
if (dp._textBox != null)
{
// Update DatePickerTextBox.Text
if (string.IsNullOrEmpty(dp._textBox.Text))
{
dp.SetWaterMarkText();
}
else
{
DateTime? date = dp.ParseText(dp._textBox.Text);
if (date != null)
{
dp.SetTextInternal(dp.DateTimeToString((DateTime)date));
}
}
}
}
#endregion SelectedDateFormat
private static bool IsValidSelectedDateFormat(object value)
{
DatePickerFormat format = (DatePickerFormat)value;
return format == DatePickerFormat.Long
|| format == DatePickerFormat.Short;
}
private string DateTimeToString(DateTime d)
{
DateTimeFormatInfo dtfi = DateTimeHelper.GetCurrentDateFormat();
switch (this.SelectedDateFormat)
{
case DatePickerFormat.Short:
{
return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.ShortDatePattern, dtfi));
}
case DatePickerFormat.Long:
{
return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.LongDatePattern, dtfi));
}
}
return null;
}
DatePickerFormat.cs
public enum DatePickerFormat
{
/// <summary>
/// Specifies that the date should be displayed
/// using unabbreviated days of the week and month names.
/// </summary>
Long = 0,
/// <summary>
/// Specifies that the date should be displayed
///using abbreviated days of the week and month names.
/// </summary>
Short = 1
}
स्रोत
2010-09-29 13:08:27
thx, इससे मुझे केवल महीने चुनने के लिए दिनांक पिकर का उपयोग करने में पूरी तरह हल करने में मदद मिली। मैंने http://stackoverflow.com/questions/1798513/wpf-toolkit-datepicker-month-year-only/14902905#14902905 में अपना xaml उद्धृत किया। – GameAlchemist
इस विधि के विशाल प्रशंसक। मैं संस्कृति को बदलने पर ऐसा करना पसंद करता हूं। – Dom
यह सच जवाब है! वर्तमान में, गंदे हैक को उत्तर के रूप में चिह्नित किया गया है। अफ़सोस की बात है। – dzendras