Skip to content

Instantly share code, notes, and snippets.

@oliverw
Last active December 17, 2015 19:09
Show Gist options
  • Save oliverw/5658814 to your computer and use it in GitHub Desktop.
Save oliverw/5658814 to your computer and use it in GitHub Desktop.
public class FooViewModel : ReactiveObject
{
DateTime dueDate;
public DateTime DueDate
{
get { return dueDate; }
set { this.RaiseAndSetIfChanged(ref dueDate, value); }
}
}
public class DueDateConverter : IBindingTypeConverter
{
#region IBindingTypeConverter implementation
public int GetAffinityForObjects(Type lhs, Type rhs)
{
// Too bad, I will never be called
throw new NotImplementedException();
}
public bool TryConvert(object from, Type toType, object conversionHint, out object result)
{
var dt = (DateTime)from;
return dt < DateTime.UtcNow ? "Date lies in the past" : "Date lies in the future";
}
#endregion
}
this.OneWayBind(ViewModel, (x)=> x.DueDate, (view)=> view.DueDateLabel.Text, null, new DueDateConverter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment