我可以将今天的日期放在标签中而不用 XAML 绑定(bind)它吗,比如
<Label Text="DateTime.Now, StringFormat='{0:MMMM dd, yyyy}'"/>
最佳答案
Can I put the date of today in a label without binding it in XAML
不,你不能。
对于绑定(bind),使用
xmlns:sys="clr-namespace:System;assembly=mscorlib"
与
<Label Content="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:MMMM dd, yyyy}'}" />
不过,您可以像 myLabelControl.Content = DateTime.Now;
这样从代码后面设置它,但我会完全避免这种情况。
关于c# - DateTime.Now 在 XAML 中没有绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42432441/