Xamarin.Formsのxamlにカスタムコントロールがあり、タイプint
のプロパティを追加したいと思います。私はBindableプロパティを使用する必要があると思うので、後でViewModelからプロパティをバインドできます。Xamarin.FormsでBindableProperty.Createを使用する方法?
私はthisトピックを見つけましたが、私はそれを使用するかどうかはわかりません...そこにある:
BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(BindablePicker), null,
propertyChanged: OnItemsSourcePropertyChanged);
「BindablePicker」何ですか?それはプロパティが宣言されているビューですか?
は、ここに私の試みです:
public int WedgeRating
{
get
{
return (int)GetValue(WedgeRatingProperty);
}
set
{
try
{
SetValue(WedgeRatingProperty, value);
}
catch (ArgumentException ex)
{
// We need to do something here to let the user know
// the value passed in failed databinding validation
}
}
}
public static readonly BindableProperty WedgeRatingProperty =
BindableProperty.Create(nameof(WedgeRating), typeof(int), typeof(GameCocosSharpView), null, propertyChanged: OnItemsSourcePropertyChanged);
private static void OnItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
}
私もXAMLでそれを使用していない、それはまだ動作しません。特別な例外はありません。カスタムコントロールが初期化されたページのみがうまくいきません。私がここにペーストした行をコメントすると、それは動作します。