从短日期到自定义格式的日期格式 [英] Date formating from short date to custom format
问题描述
作为主题我有contentpresenter如何在调度程序中显示日期这个默认的contentTemplate以简短格式显示日期,但我想以自定义格式显示日期:
示例:
默认的ContentPresenter:
< contentcontrol x:name =Content margin = - 2content ={TemplateBinding Content}xmlns:x =#unknown>
HorizontalContentAlignment =Center
VerticalContentAlignment =Center />
this.xaml以此格式显示日期:12/02/2013
但是我想改变它以显示这个:04星期二
为了达到这个目的我应该改变什么?
和thx为你所有人提供帮助。
抱歉 guys i my 问题
12/02/2013 convert 12 Tue 。
xaml show date this format: 12/02/2013
但 我 想要 更改 order show this: 12 Tue 。
你可以使用<$ c绑定中的$ c> StringFormat 可以更改显示方式。因为你的例子不匹配 - 即04 Tue与12/02/2013不一样,我看不出你是如何推导出来的,我不能给你一个确切的字符串。但是,您可以首先阅读XAML中的WPF和 StringFormat
。
执行此操作的简单方法是使用String。格式(),您可以在这里阅读更多信息:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
但是,如果您使用的是XAML数据绑定(我假设你来自上面的代码片段),你可以在你的绑定语句中添加一个转换器来制作你想要的任何格式。你可以在这里阅读更多相关内容:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/ca42be91-3d72-46e5-8624-9610a97cce71
我确实这样做并且有效:
< contentcontrol x:name =Contentmargin = - 2content ={TemplateBinding Content}xmlns:x = #unknown>
ContentTemplate ={DynamicResource LabelTemplate}
HorizontalContentAlignment =Center
VerticalContentAlignment =Center/>
i和ContentTemplate引用labelTemplate
< datatemplate x:key =LabelTemplate>
Hi,
All as the subject i have contentpresenter how show date in scheduler view this default contentTemplate show date in short format but i want to show the daate in custom format:
example:
the default ContentPresenter:
<contentcontrol x:name="Content" margin="-2" content="{TemplateBinding Content}" xmlns:x="#unknown">
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" />
this.xaml show the date in this format: 12/02/2013
but i want to change this in order to show this: 04 Tue.
what should i change in order to reach this object???
and thx for all you helps.
[Edit: Moved from OP''s Answer]
Sorry guys i have an error in my question
12/02/2013 is should convert to 12 Tue.
xaml show the date in this format: 12/02/2013
but i want to change this in order to show this: 12 Tue.
You can use aStringFormat
in your binding to change the way that this is displayed. As your example doesn''t match - i.e. 04 Tue isn''t the same as 12/02/2013 and I can''t see how you derives this, I can''t give you the exact string. However, you could start by reading up about WPF andStringFormat
in XAML.
The simple way to do this is to use String.Format(), which you can read more about here:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
However, if you are using XAML databinding (as I assume you are from the code snippet above), you can add a converter to your binding statement to make any format you''d like. You can read more about that here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/ca42be91-3d72-46e5-8624-9610a97cce71
i did do this and it is worked:
<contentcontrol x:name="Content" margin="-2" content="{TemplateBinding Content}" xmlns:x="#unknown">
ContentTemplate="{DynamicResource LabelTemplate}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" />
i did and ContentTemplate referred to labelTemplate
<datatemplate x:key="LabelTemplate">
这篇关于从短日期到自定义格式的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!