私はXamarin.formsを使ってアプリケーションを作成しています。整数のBindablePropertyのセッターは、xaml(Xamarin.forms)から呼び出されたことはありません
BindablePropertyを整数に設定しました。 しかし、セッターは決して呼び出されず、xamlからもセットされません。
<... SelectedIndex="{Binding myValue}">
何か問題がありますか?
ありがとうございました。
public class CircleSegmentControl : StackLayout
{
public static readonly BindableProperty SegmentInitialIndexProperty = BindableProperty.Create("SelectedIndex", typeof(int), typeof(CircleSegmentControl), 0);
public int SelectedIndex {
set{
Debug.WriteLine("setter");
SetValue(SegmentInitialIndexProperty, value);
SelectIndex(value);
}
get{
Debug.WriteLine("getter");
return (int)GetValue(SegmentInitialIndexProperty);
}
}
...
}
Xamarinについてはわかりませんが、おそらくWPF依存プロパティと同じ問題があります。プロパティラッパーの 'get'メソッドと' set'メソッドで 'GetValue'と' SetValue'以外を呼び出さないでください。プロパティ値の変更( 'SelectIndex'メソッドを呼び出す)を通知するには、' BindableProperty.Create'の別のオーバーロードで 'propertyChanged'デリゲートを登録する必要があります。 – Clemens
@クレメンスありがとう。あなたの答えは正しい!これは、propertyChangedデリゲートで呼び出されます。 –