0
我们的系统中有几个BindableProperties。他们大部分都在工作,而我之前没有遇到过这个问题。我正在测试UWP,但其他平台上的问题可能相同。Xamarin Forms - BindableProperty不工作
你可以看到在这里下载代码,看看到底是什么我谈论 https://[email protected]/ChristianFindlay/xamarin-forms-scratch.git
这里是我的代码:
public class ExtendedEntry : Entry
{
public static readonly BindableProperty TestProperty =
BindableProperty.Create<ExtendedEntry, int>
(
p => p.Test,
0,
BindingMode.TwoWay,
propertyChanging: TestChanging
);
public int Test
{
get
{
return (int)GetValue(TestProperty);
}
set
{
SetValue(TestProperty, value);
}
}
private static void TestChanging(BindableObject bindable, int oldValue, int newValue)
{
var ctrl = (ExtendedEntry)bindable;
ctrl.Test = newValue;
}
}
这是XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TestXamarinForms"
x:Class="TestXamarinForms.BindablePropertyPage">
<ContentPage.Content>
<StackLayout>
<local:ExtendedEntry Test="1" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
我可以看到在Test的setter中,1被传递给SetValue。但是,在下一行中,我查看GetValue作为监视窗口中的属性,并且值为0. BindableProperty不会粘住。我试着用几个不同的Create重载实例化BindingProperty,但似乎没有任何工作。我究竟做错了什么?