[NUI][NUI.Devel] Update nui line coverage TCs.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Xaml / TotalSample / BindingSample.xaml.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using System.Globalization;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22
23 namespace Tizen.NUI.Devel.Tests
24 {
25     public class FloatToBoolConverter : IValueConverter
26     {
27         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
28         {
29             return (float)value != 0;
30         }
31
32         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
33         {
34             return (bool)value ? 1 : 0;
35         }
36     }
37
38     public class BoolToObjectConverter<T> : IValueConverter
39     {
40         public T TrueObject { set; get; }
41
42         public T FalseObject { set; get; }
43
44         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
45         {
46             return (bool)value ? TrueObject : FalseObject;
47         }
48
49         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
50         {
51             return ((T)value).Equals(TrueObject);
52         }
53     }
54
55     public class FloatToIntConverter : IValueConverter
56     {
57         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
58         {
59             return (int)Math.Round((float)value * GetParameter(parameter));
60         }
61
62         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
63         {
64             return (int)value / GetParameter(parameter);
65         }
66
67         float GetParameter(object parameter)
68         {
69             if (parameter is float)
70             {
71                 return (float)parameter;
72             }
73             else if (parameter is int)
74             {
75                 return (int)parameter;
76             }
77             else if (parameter is string)
78             {
79                 return float.Parse((string)parameter);
80             }
81
82             return 1;
83         }
84     }
85
86     public class RgbColorViewModel : INotifyPropertyChanged
87     {
88         Color color;
89         string name;
90
91         public event PropertyChangedEventHandler PropertyChanged;
92
93         public float Red
94         {
95             set
96             {
97                 if (color.R != value)
98                 {
99                     Color = new Color(value, color.G, color.B, 1.0f);
100                 }
101             }
102             get => color.R;
103         }
104
105
106         public Color Color
107         {
108             set
109             {
110                 if (color != value)
111                 {
112                     color = value;
113                     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Red"));
114                     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Color"));
115
116                     Name = "Red";
117                 }
118             }
119             get => color;
120         }
121
122         public string Name
123         {
124             private set
125             {
126                 if (name != value)
127                 {
128                     name = value;
129                     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
130                 }
131             }
132             get => name;
133         }
134     }
135
136     public partial class BindingSample : View
137     {
138         public BindingSample()
139         {
140             global::Tizen.NUI.Xaml.Extensions.LoadFromXaml(this, typeof(BindingSample));
141         }
142     }
143 }