【发布时间】:2012-11-10 05:35:09
【问题描述】:
我有一个 ListBox,其中包含整个绑定对象被传递给转换器(需要),并且该对象似乎没有正确更新。这是相关的 XAML
<TextBlock
Text="{Binding Converter={StaticResource DueConverter}}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneDisabledBrush}" />
还有转换器
public class DueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return null;
Task task = (Task)value;
if (task.HasReminders)
{
return task.Due.Date.ToShortDateString() + " " + task.Due.ToShortTimeString();
}
else
{
return task.Due.Date.ToShortDateString();
}
}
//Called with two-way data binding as value is pulled out of control and put back into the property
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
最后是数据模型中的到期日期时间。
private DateTime _due;
[Column(CanBeNull=false)]
public DateTime Due
{
get { return _due; }
set
{
if (_due != value)
{
NotifyPropertyChanging("Due");
_due = value;
NotifyPropertyChanged("Due");
}
}
}
NotifyPropertyChanging/Changed 起作用,因为绑定到不同属性的其他控件正确更新。
我的目标是在到期时更新 TextBlock 的到期日期,但输出的格式取决于 Task 对象的另一个属性。
有什么想法吗?
【问题讨论】:
-
一般来说,SO协议是不把标签放在问题标题中的。我已经更新了你的标题并重新标记了这个问题。
标签: c# binding converter windows-phone