Bri*_*Lee 1 xaml binding xamarin xamarin.forms
我正在使用 Xamarin.forms 制作应用程序。
我将 BindableProperty 设置为整数。但它的 setter 从未被调用,甚至没有从 xaml 设置。
<... SelectedIndex="{Binding myValue}">
Run Code Online (Sandbox Code Playgroud)
我是不是做错了什么?
谢谢。
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);
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
显然,这同样适用于 WPF 依赖属性。除了属性包装器的和方法中的GetValue和之外,您不得调用任何其他内容:SetValuegetset
public int SelectedIndex
{
get { return (int)GetValue(SelectedIndexProperty); }
set { SetValue(SelectedIndexProperty, value); }
}
Run Code Online (Sandbox Code Playgroud)
要获得有关属性值更改的通知(以调用您的SelectIndex方法),您应该propertyChanged使用BindableProperty.Create.
| 归档时间: |
|
| 查看次数: |
1677 次 |
| 最近记录: |