Skip to content

Instantly share code, notes, and snippets.

@lbugnion
Created January 27, 2016 21:04
Show Gist options
  • Save lbugnion/db7789d29136d510549b to your computer and use it in GitHub Desktop.
Save lbugnion/db7789d29136d510549b to your computer and use it in GitHub Desktop.
MVVM Light binding framework for Xamarin also supports FallbackValue and TargetNullValue
[Test]
public void BindingDeepPath_DeepSourceExistingPathGraduallySettingPath_NoError()
{
VmSource = new TestViewModel();
VmTarget = new TestViewModel();
const string fallback = "This is the fallback";
const string targetNull = "Target is null";
var binding = new Helpers.Binding<string, string>(
VmSource,
() => VmSource.Nested.Nested.Model.MyProperty,
VmTarget,
() => VmTarget.TargetProperty,
fallbackValue: fallback,
targetNullValue: targetNull);
Assert.AreEqual(fallback, VmTarget.TargetProperty);
VmSource.Nested = new TestViewModel();
Assert.AreEqual(fallback, VmTarget.TargetProperty);
VmSource.Nested.Nested = new TestViewModel();
Assert.AreEqual(fallback, VmTarget.TargetProperty);
VmSource.Nested.Nested.Model = new TestModel();
Assert.AreEqual(targetNull, VmTarget.TargetProperty);
var initialValue = "Initial value";
VmSource.Nested.Nested.Model.MyProperty = initialValue;
Assert.AreEqual(initialValue, VmTarget.TargetProperty);
var newValue = DateTime.Now.Ticks.ToString();
VmSource.Nested.Nested.Model.MyProperty = newValue;
Assert.AreEqual(newValue, VmTarget.TargetProperty);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment