【发布时间】:2016-09-03 10:05:28
【问题描述】:
我正在使用 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方法),您应该注册一个propertyChanged委托和另一个重载BindableProperty.Create。 -
@Clemens 谢谢。你的答案是正确的!它在 propertyChanged 委托中调用。
标签: xaml xamarin binding xamarin.forms