Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 6945176

Browse files
committed
Code layout fixed.
1 parent 70ad629 commit 6945176

File tree

4 files changed

+102
-80
lines changed

4 files changed

+102
-80
lines changed

XAML/ValidationCallback/ValidationCallback/App.cs

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class App : Application
88
{
99
public App ()
1010
{
11-
MainPage = new HomePage ();
11+
MainPage = new HomePage();
1212
}
1313

1414
protected override void OnStart ()
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ValidationCallback.HomePage" x:Name="page">
3-
<StackLayout Padding="0,20,0,0" BindingContext="{x:Reference page}">
4-
<Label Text="Bindable Property Validation Callback Demo" FontAttributes="Bold" HorizontalOptions="Center" />
5-
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
6-
<Label Text="Rotation angle:" />
7-
<Entry Text="{Binding Angle}" WidthRequest="50" />
8-
</StackLayout>
9-
<Image Source="waterfront.jpg" Rotation="{Binding Angle}" VerticalOptions="CenterAndExpand" />
10-
</StackLayout>
2+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="ValidationCallback.HomePage"
5+
x:Name="page">
6+
<StackLayout Margin="0,35,0,0"
7+
BindingContext="{x:Reference page}">
8+
<Label Text="Bindable Property Validation Callback Demo"
9+
FontAttributes="Bold"
10+
HorizontalOptions="Center" />
11+
<StackLayout Orientation="Horizontal"
12+
HorizontalOptions="Center">
13+
<Label Text="Rotation angle:" />
14+
<Entry Text="{Binding Angle}"
15+
WidthRequest="50" />
16+
</StackLayout>
17+
<Image Source="waterfront.jpg"
18+
Rotation="{Binding Angle}"
19+
VerticalOptions="CenterAndExpand" />
20+
</StackLayout>
1121
</ContentPage>

XAML/ValidationCallback/ValidationCallback/HomePage.xaml.cs

100755100644
Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,33 @@
22

33
namespace ValidationCallback
44
{
5-
public partial class HomePage : ContentPage
6-
{
7-
public static readonly BindableProperty AngleProperty = BindableProperty.Create ("Angle", typeof(double), typeof(HomePage), 0.0, validateValue: IsValidValue);
5+
public partial class HomePage : ContentPage
6+
{
7+
public static readonly BindableProperty AngleProperty = BindableProperty.Create("Angle", typeof(double), typeof(HomePage), 0.0, validateValue: IsValidValue);
88

9-
public double Angle {
10-
get { return (double)GetValue (AngleProperty); }
11-
set { SetValue (AngleProperty, value); }
12-
}
9+
public double Angle
10+
{
11+
get { return (double)GetValue(AngleProperty); }
12+
set
13+
{
14+
if (IsValidValue(null, value))
15+
{
16+
SetValue(AngleProperty, value);
17+
}
18+
}
19+
}
1320

14-
public HomePage ()
15-
{
16-
InitializeComponent ();
17-
}
21+
public HomePage()
22+
{
23+
InitializeComponent();
24+
}
1825

19-
static bool IsValidValue (BindableObject view, object value)
20-
{
21-
double result;
22-
bool isDouble = double.TryParse (value.ToString (), out result);
23-
return (result >= 0 && result <= 360);
24-
}
25-
}
26+
static bool IsValidValue(BindableObject view, object value)
27+
{
28+
double result;
29+
double.TryParse(value.ToString(), out result);
30+
return (result >= 0 && result <= 360);
31+
}
32+
}
2633
}
2734

XAML/ValidationCallback/ValidationCallback/HomePageCS.cs

100755100644
Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,67 @@
22

33
namespace ValidationCallback
44
{
5-
public class HomePageCS : ContentPage
6-
{
7-
public static readonly BindableProperty AngleProperty = BindableProperty.Create ("Angle", typeof(double), typeof(HomePage), 0.0, validateValue: IsValidValue);
5+
public class HomePageCS : ContentPage
6+
{
7+
public static readonly BindableProperty AngleProperty = BindableProperty.Create("Angle", typeof(double), typeof(HomePage), 0.0, validateValue: IsValidValue);
88

9-
public double Angle {
10-
get {
11-
return (double)GetValue(AngleProperty);
12-
}
13-
set {
14-
try {
15-
SetValue(AngleProperty, value);
16-
} catch {
17-
DisplayAlert ("Alert", "Angle must be between 0-360", "OK");
18-
}
19-
}
9+
public double Angle
10+
{
11+
get
12+
{
13+
return (double)GetValue(AngleProperty);
14+
}
15+
set
16+
{
17+
if (IsValidValue(null, value))
18+
{
19+
SetValue(AngleProperty, value);
20+
}
21+
}
22+
}
2023

21-
}
24+
public HomePageCS()
25+
{
26+
BindingContext = this;
2227

23-
public HomePageCS ()
24-
{
25-
BindingContext = this;
28+
var angleEntry = new Entry { WidthRequest = 50 };
29+
angleEntry.SetBinding(Entry.TextProperty, "Angle");
2630

27-
var angleEntry = new Entry { WidthRequest = 50 };
28-
angleEntry.SetBinding(Entry.TextProperty, "Angle");
31+
var image = new Image { VerticalOptions = LayoutOptions.CenterAndExpand };
32+
image.Source = ImageSource.FromFile("waterfront.jpg");
33+
image.SetBinding(VisualElement.RotationProperty, "Angle");
2934

30-
var image = new Image { VerticalOptions = LayoutOptions.CenterAndExpand };
31-
image.Source = ImageSource.FromFile("waterfront.jpg");
32-
image.SetBinding(VisualElement.RotationProperty, "Angle");
35+
Content = new StackLayout
36+
{
37+
Margin = new Thickness(0, 35, 0, 0),
38+
Children =
39+
{
40+
new Label
41+
{
42+
Text = "Bindable Property Validation Callback Demo",
43+
FontAttributes = FontAttributes.Bold,
44+
HorizontalOptions = LayoutOptions.Center
45+
},
46+
new StackLayout
47+
{
48+
Orientation = StackOrientation.Horizontal,
49+
HorizontalOptions = LayoutOptions.Center,
50+
Children =
51+
{
52+
new Label { Text = "Rotation angle:" },
53+
angleEntry
54+
}
55+
},
56+
image
57+
}
58+
};
59+
}
3360

34-
Content = new StackLayout
35-
{
36-
Padding = new Thickness(0, 20, 0, 0),
37-
Children = {
38-
new Label {
39-
Text = "Bindable Property Validation Callback Demo",
40-
FontAttributes = FontAttributes.Bold,
41-
HorizontalOptions = LayoutOptions.Center
42-
},
43-
new StackLayout {
44-
Orientation = StackOrientation.Horizontal,
45-
HorizontalOptions = LayoutOptions.Center,
46-
Children = {
47-
new Label { Text = "Rotation angle:" },
48-
angleEntry
49-
}
50-
},
51-
image
52-
}
53-
};
54-
}
55-
56-
static bool IsValidValue (BindableObject view, object value)
57-
{
58-
double result;
59-
bool isDouble = double.TryParse (value.ToString (), out result);
60-
return (result >= 0 && result <= 360);
61-
}
62-
}
61+
static bool IsValidValue(BindableObject view, object value)
62+
{
63+
double result;
64+
double.TryParse(value.ToString(), out result);
65+
return (result >= 0 && result <= 360);
66+
}
67+
}
6368
}

0 commit comments

Comments
 (0)