diff options
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs')
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs new file mode 100644 index 00000000..3548fc14 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz29300DummyView : StackLayout + { + public static readonly BindableProperty NumOfRepeatProperty = + BindableProperty.Create<Bz29300DummyView, int> (p => p.NumOfRepeat, 1, BindingMode.OneWay, null, UpdateTexts); + + public static readonly BindableProperty TextProperty = + BindableProperty.Create<Bz29300DummyView, string> (p => p.Text, string.Empty, BindingMode.OneWay, null, UpdateTexts); + + public int NumOfRepeat + { + get { return (int)GetValue(NumOfRepeatProperty); } + set { SetValue(NumOfRepeatProperty, value); } + } + + public string Text + { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + + public Bz29300DummyView() + { + } + + static void UpdateTexts(BindableObject bindable, string oldValue, string newValue) + { + var instance = bindable as Bz29300DummyView; + instance.Children.Clear(); + for (int i = 0; i < instance.NumOfRepeat; i++) + instance.Children.Add(new Label() {Text = newValue }); + } + + static void UpdateTexts(BindableObject bindable, int oldValue, int newValue) + { + var instance = bindable as Bz29300DummyView; + if (oldValue == newValue) + return; + if (oldValue > newValue) { + for (int i = newValue; i > oldValue; i--) + instance.Children.RemoveAt(0); + } else { + for (int i = oldValue; i < newValue; i++) + instance.Children.Add(new Label() { Text = instance.Text }); + } + } + } + + public partial class Bz29300 : ContentPage + { + public Bz29300 () + { + InitializeComponent (); + } + + public Bz29300 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void AccessUserDefinedBindableProperties (bool useCompiledXaml) + { + var layout = new Bz29300 (useCompiledXaml); + Assert.AreEqual (4, layout.dummy.NumOfRepeat); + Assert.AreEqual ("Test", layout.dummy.Text); + } + } + } +}
\ No newline at end of file |