gpt4 book ai didi

c# - UWP x :Bind with time

转载 作者:可可西里 更新时间:2023-11-01 11:49:51 24 4
gpt4 key购买 nike

我将我的应用程序从 WP 8.1/W 8.1 转换为 UWP。它包括一个更新文本框值的计时器。这是 XAML:

Text="{Binding CurrentLocalDateTime, Mode=TwoWay, Converter={StaticResource DateTimeConverter}}"

和数据上下文:

    private DateTime currentLocalDateTime;

public DateTime CurrentLocalDateTime { get { return currentLocalDateTime; } set { currentLocalDateTime = value; OnPropertyChanged("CurrentLocalDateTime"); } }

private void TimerExecution(object sender, object e)
{
CurrentLocalDateTime = DateTime.Now;
}

我想使用新的 x:Bind 绑定(bind)方式,但控件永远不会更新,代码如下:

Text="{x:Bind CurrentLocalDateTime, Mode=TwoWay, Converter={StaticResource DateTimeConverter}}"

数据上下文:

    public DateTime CurrentLocalDateTime { get; set; }

private void TimerExecution(object sender, object e)
{
CurrentLocalDateTime = DateTime.Now;
}

怎么了?

非常感谢您的帮助。问候

最佳答案

当您设置 CurrentLocalDateTime 时,没有任何东西可以通知您的 UI 它发生了。它适用于第一种情况,因为您正在实现 INotifyPropertyChanged 并使用属性名称调用 OnPropertyChanged。

public DateTime CurrentLocalDateTime 
{
get { return currentLocalDateTime; }
set
{
currentLocalDateTime = value;
OnPropertyChanged("CurrentLocalDateTime");
}
}

关于c# - UWP x :Bind with time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32727735/

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