更改WPF DatePicker的字符串格式 [英] Changing the string format of the WPF DatePicker
本文介绍了更改WPF DatePicker的字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改WPF工具包DatePicker中DatePickerTextBox的字符串格式,以使用连字符而不是分隔符的斜杠。
有没有办法覆盖这个默认文化或显示字符串格式?
01-01-2010
/ pre>
解决方案我已经通过这段代码帮助解决了这个问题。希望它也会帮助你。
< Style TargetType ={x:Type DatePickerTextBox}>
< Setter Property =Control.Template>
< Setter.Value>
< ControlTemplate>
< TextBox x:Name =PART_TextBox
Text ={Binding Path = SelectedDate,StringFormat ='dd MMM yyyy',
RelativeSource = {RelativeSource AncestorType = {x:Type DatePicker }}}/>
< / ControlTemplate>
< /Setter.Value>
< / Setter>
< / Style>
I need to change the string format of the DatePickerTextBox in the WPF Toolkit DatePicker, to use hyphens instead of slashes for the seperators.
Is there a way to override this default culture or the display string format?
01-01-2010
解决方案I have solved this problem with a help of this code. Hope it will help you all as well.
<Style TargetType="{x:Type DatePickerTextBox}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <TextBox x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, StringFormat='dd MMM yyyy', RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" /> </ControlTemplate> </Setter.Value> </Setter> </Style>
这篇关于更改WPF DatePicker的字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文