Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Replace obsolete generic BindableProperty Create's
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Petzold committed Jan 29, 2016
1 parent b48fc26 commit 1786d20
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 65 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,46 @@ namespace Xamarin.FormsBook.Toolkit
public partial class CheckBox : ContentView
{
public static readonly BindableProperty TextProperty =
BindableProperty.Create<CheckBox, string>(
checkbox => checkbox.Text,
BindableProperty.Create(
"Text",
typeof(string),
typeof(CheckBox),
null,
propertyChanged: (bindable, oldValue, newValue) =>
{
((CheckBox)bindable).textLabel.Text = (string)newValue;
});

public static readonly BindableProperty FontSizeProperty =
BindableProperty.Create<CheckBox, double>(
checkbox => checkbox.FontSize,
BindableProperty.Create(
"FontSize",
typeof(double),
typeof(CheckBox),
Device.GetNamedSize(NamedSize.Default, typeof(Label)),
propertyChanged: (bindable, oldValue, newValue) =>
{
CheckBox checkbox = (CheckBox)bindable;
checkbox.boxLabel.FontSize = newValue;
checkbox.textLabel.FontSize = newValue;
checkbox.boxLabel.FontSize = (double)newValue;
checkbox.textLabel.FontSize = (double)newValue;
});

public static readonly BindableProperty IsCheckedProperty =
BindableProperty.Create<CheckBox, bool>(
checkbox => checkbox.IsChecked,
BindableProperty.Create(
"IsChecked",
typeof(bool),
typeof(CheckBox),
false,
propertyChanged: (bindable, oldValue, newValue) =>
{
// Set the graphic.
CheckBox checkbox = (CheckBox)bindable;
checkbox.boxLabel.Text = newValue ? "\u2611" : "\u2610";
checkbox.boxLabel.Text = (bool)newValue ? "\u2611" : "\u2610";
// Fire the event.
EventHandler<bool> eventHandler = checkbox.CheckedChanged;
if (eventHandler != null)
{
eventHandler(checkbox, newValue);
eventHandler(checkbox, (bool)newValue);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public NewCheckBox()

// Text property.
public static readonly BindableProperty TextProperty =
BindableProperty.Create<NewCheckBox, string>(
checkbox => checkbox.Text,
BindableProperty.Create(
"Text",
typeof(string),
typeof(NewCheckBox),
null);

public string Text
Expand All @@ -26,8 +28,10 @@ public string Text

// TextColor property.
public static readonly BindableProperty TextColorProperty =
BindableProperty.Create<NewCheckBox, Color>(
checkbox => checkbox.TextColor,
BindableProperty.Create(
"TextColor",
typeof(Color),
typeof(NewCheckBox),
Color.Default);

public Color TextColor
Expand All @@ -38,8 +42,10 @@ public Color TextColor

// FontSize property.
public static readonly BindableProperty FontSizeProperty =
BindableProperty.Create<NewCheckBox, double>(
checkbox => checkbox.FontSize,
BindableProperty.Create(
"FontSize",
typeof(double),
typeof(NewCheckBox),
Device.GetNamedSize(NamedSize.Default, typeof(Label)));

[TypeConverter(typeof(FontSizeConverter))]
Expand All @@ -51,8 +57,10 @@ public double FontSize

// FontAttributes property.
public static readonly BindableProperty FontAttributesProperty =
BindableProperty.Create<NewCheckBox, FontAttributes>(
checkbox => checkbox.FontAttributes,
BindableProperty.Create(
"FontAttributes",
typeof(FontAttributes),
typeof(NewCheckBox),
FontAttributes.None);

public FontAttributes FontAttributes
Expand All @@ -63,8 +71,10 @@ public FontAttributes FontAttributes

// IsChecked property.
public static readonly BindableProperty IsCheckedProperty =
BindableProperty.Create<NewCheckBox, bool>(
checkbox => checkbox.IsChecked,
BindableProperty.Create(
"IsChecked",
typeof(bool),
typeof(NewCheckBox),
false,
propertyChanged: (bindable, oldValue, newValue) =>
{
Expand All @@ -73,7 +83,7 @@ public FontAttributes FontAttributes
EventHandler<bool> eventHandler = checkbox.CheckedChanged;
if (eventHandler != null)
{
eventHandler(checkbox, newValue);
eventHandler(checkbox, (bool)newValue);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ namespace Xamarin.FormsBook.Toolkit
public partial class PickerCell : ViewCell
{
public static readonly BindableProperty LabelProperty =
BindableProperty.Create<PickerCell, string>(
cell => cell.Label, default(string));
BindableProperty.Create(
"Label", typeof(string), typeof(PickerCell), default(string));

public static readonly BindableProperty TitleProperty =
BindableProperty.Create<PickerCell, string>
(cell => cell.Title, default(string));
BindableProperty.Create(
"Title", typeof(string), typeof(PickerCell), default(string));

public static readonly BindableProperty SelectedValueProperty =
BindableProperty.Create<PickerCell, string>
(cell => cell.SelectedValue,
null, BindingMode.TwoWay, null,
BindableProperty.Create(
"SelectedValue", typeof(string), typeof(PickerCell), null,
BindingMode.TwoWay,
propertyChanged: (sender, oldValue, newValue) =>
{
PickerCell pickerCell = (PickerCell)sender;
if (String.IsNullOrEmpty(newValue))
if (String.IsNullOrEmpty((string)newValue))
{
pickerCell.picker.SelectedIndex = -1;
}
else
{
pickerCell.picker.SelectedIndex =
pickerCell.Items.IndexOf(newValue);
pickerCell.Items.IndexOf((string)newValue);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class ToggleBehavior : Behavior<View>
TapGestureRecognizer tapRecognizer;

public static readonly BindableProperty IsToggledProperty =
BindableProperty.Create<ToggleBehavior, bool>(tb => tb.IsToggled, false);
BindableProperty.Create(
"IsToggled", typeof(bool), typeof(ToggleBehavior), false);

public bool IsToggled
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<ItemGroup>
<Compile Include="AdderViewModel.cs" />
<Compile Include="AltLabel.cs" />
<Compile Include="AltLabelGeneric.cs" />
<Compile Include="AnalogClockViewModel.cs" />
<Compile Include="BaseTwoLogConverter.cs" />
<Compile Include="BezierSpline.cs" />
Expand Down

0 comments on commit 1786d20

Please sign in to comment.