バインドされたオブジェクト全体がコンバーターに渡される (必要な) 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();
}
}
最後に、データ モデルからの予定の DateTime です。
private DateTime _due;
[Column(CanBeNull=false)]
public DateTime Due
{
get { return _due; }
set
{
if (_due != value)
{
NotifyPropertyChanging("Due");
_due = value;
NotifyPropertyChanged("Due");
}
}
}
異なるプロパティにバインドされた他のコントロールが正しく更新されるため、NotifyPropertyChanging/Changed が機能します。
私の目標は、Due が変更されるたびに期限日 TextBlock を更新することですが、出力の形式は Task オブジェクトの別のプロパティに依存します。
何かご意見は?