gpt4 book ai didi

wpf - 日期字符串格式绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-12-01 06:11:23 27 4
gpt4 key购买 nike

我试图将日期格式设置为“MM/dd/yyyy”,但是,当前日期格式也随时间而来,我尝试使用以下代码对其进行格式化,但它没有改变,请问纠正我如下:

<DataGridTextColumn Header="Bill Date" Binding="{Binding BillDate, StringFormat={}{0:MM/dd/yyyy}}" Width="90" IsReadOnly="True" />

        <DataGridTemplateColumn Header="Bill Date" Width="90">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding BillDate}" ContentStringFormat="MM/dd/yyyy" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

我的属性(property)代码如下:

Property BillDate As Date
Get
Return _BillDate
End Get
Set(Value As Date)
If Not _BillDate = Value Then
_BillDate = Value
NotifyPropertyChanged("BillDate")
End If
End Set
End Property

我不想在属性级别进行更正,我只想在 XAML 中显示格式,上面的格式不起作用,尽管据我所知它是正确的。

编辑:经过多次尝试和一些经验之后,我开始知道解决方案不是构建任何新代码。所以,现在的问题是——新的、修改过的 xaml 没有被构建。你能帮我做这件事吗?

最佳答案

尝试

"{Binding BillDate, StringFormat=d}"

这应该给你月/日/年作为输出。

更新

控件 LabelContent 属性是对象类型,不像字符串那样应用格式。这是您的选择,

使用 ContentStringFormat标签上的属性:

<Label ContentStringFormat="d">
<system:DateTime>2015/3/4 13:6:55</system:DateTime>
</Label>

或者TextBox控件,Text属性是一个字符串,它接受格式化参数。

关于wpf - 日期字符串格式绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com