UWP x:Bind 随着时间的推移
UWP x:Bind with time
我将我的应用程序从 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 合并方式,但控件永远不会更新,代码如下:
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");
}
}
我将我的应用程序从 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 合并方式,但控件永远不会更新,代码如下:
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");
}
}