Wpf xaml日期格式字符串已忽略
我的标签上显示的是“2010年7月27日”,而不是“2010年7月27日”。有人能告诉我为什么我的标记代码被忽略了吗Wpf xaml日期格式字符串已忽略,wpf,xaml,Wpf,Xaml,我的标签上显示的是“2010年7月27日”,而不是“2010年7月27日”。有人能告诉我为什么我的标记代码被忽略了吗 RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='{}{0:MMMM d, yyyy}'}" 干杯, Berryl仅当绑定应用于String类型的属性时,才使用StringFormat属性。由于内容的类型为object,因此不使用它。与其直接将内容设置为日期,不如
RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='{}{0:MMMM d, yyyy}'}"
干杯,Berryl仅当绑定应用于String类型的属性时,才使用StringFormat属性。由于内容的类型为object,因此不使用它。与其直接将内容设置为日期,不如将其设置为TextBlock,并使用StringFormat设置TextBlock的Text属性:
<RibbonLabel>
<TextBlock Text="{Binding Source={x:Static sys:DateTime.Today},
StringFormat='{}{0:MMMM d, yyyy}'}"/>
</RibbonLabel>
您还可以为DateTime定义一个DataTemplate,然后将内容设置为“今天”:
<Window.Resources>
<DataTemplate DataType="{x:Type sys:DateTime}">
<TextBlock Text="{Binding StringFormat='{}{0:MMMM d, yyyy}'}"/>
</DataTemplate>
</Window.Resources>
...
<RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}}">
...
编辑:更简单的解决方案是使用ContentStringFormat属性
<RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}}"
ContentStringFormat="{}{0:MMMM d, yyyy}" />
你是救命恩人。非常感谢