1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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 =
#pragma warning disable 618
BindableProperty.Create<Bz29300DummyView, int> (p => p.NumOfRepeat, 1, BindingMode.OneWay, null, UpdateTexts);
#pragma warning restore 618
public static readonly BindableProperty TextProperty =
#pragma warning disable 618
BindableProperty.Create<Bz29300DummyView, string> (p => p.Text, string.Empty, BindingMode.OneWay, null, UpdateTexts);
#pragma warning restore 618
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);
}
}
}
}
|