}
[Test]
+ //https://github.com/xamarin/Xamarin.Forms/issues/4103
+ public void TestTargetNullValue()
+ {
+ var property = BindableProperty.Create("Text", typeof(string), typeof(MockBindable), default(string));
+ var binding = new TypedBinding<MockViewModel, string>(vm => vm.Text, null, null) { TargetNullValue = "target null"};
+ var bindable = new MockBindable();
+ bindable.SetBinding(property, binding);
+ bindable.BindingContext = new MockViewModel("initial");
+ Assert.That(bindable.GetValue(property), Is.EqualTo("initial"));
+
+ bindable.BindingContext = new MockViewModel(null);
+ Assert.That(bindable.GetValue(property), Is.EqualTo("target null"));
+
+ }
+
+ [Test]
[Description("OneWay bindings should not double apply on source updates.")]
public void OneWayBindingsDontDoubleApplyOnSourceUpdates()
{
if (Converter != null)
value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
- //return base.GetSourceValue(value, targetPropertyType);
- if (StringFormat != null)
- return string.Format(StringFormat, value);
-
- return value;
+ return base.GetSourceValue(value, targetPropertyType);
}
internal override object GetTargetValue(object value, Type sourcePropertyType)
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage
+ xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="using:Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Gh4103"
+ x:DataType="local:Gh4103VM">
+ <Label x:Name="label" Text="{Binding SomeNullableValue, TargetNullValue='target null', FallbackValue='fallback'}"/>
+</ContentPage>
--- /dev/null
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using Xamarin.Forms;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public class Gh4103VM
+ {
+ public string SomeNullableValue { get; set; } = "initial";
+ }
+ public partial class Gh4103 : ContentPage
+ {
+ private string _someNullableValue = "initial";
+
+ public Gh4103()
+ {
+ InitializeComponent();
+ }
+
+ public Gh4103(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ class Tests
+ {
+ [SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices();
+ [TearDown] public void TearDown() => Device.PlatformServices = null;
+
+ [TestCase(true), TestCase(false)]
+ public void CompiledBindingsTargetNullValue(bool useCompiledXaml)
+ {
+ var layout = new Gh4103(useCompiledXaml) { BindingContext = new Gh4103VM() };
+ Assert.That(layout.label.Text, Is.EqualTo("initial"));
+
+ layout.BindingContext = new Gh4103VM { SomeNullableValue = null };
+ Assert.That(layout.label.Text, Is.EqualTo("target null"));
+ }
+ }
+ }
+}
\ No newline at end of file