【发布时间】:2016-12-29 17:02:18
【问题描述】:
我正在尝试以这种方式在 Xamarin.Forms for iOS 中禁用 SwitchCell:
<SwitchCell x:Name="mySC" Text="Foo" OnChanged="myFnc"/>
<SwitchCell.IsEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</SwitchCell.IsEnabled>
当我在 iOS 模拟器上运行此代码时,会引发异常:
System.Reflection.TargetInvocationException:已抛出异常 通过调用的目标。 ---> System.NullReferenceException: 你调用的对象是空的 在 Xamarin.Forms.Cell.OnIsEnabledPropertyChanged(Xamarin.Forms.BindableObject 可绑定,System.Object oldvalue, System.Object newvalue) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Cells\Cell.cs:197
如果我将OnPlatform.iOS 的值设置为true,它就可以工作。如果我不使用OnPlatform 标签并为所有平台设置例如IsEnabled="false",它运行良好 - 假设是关于 iOS 模拟器中的错误。
【问题讨论】:
标签: c# xamarin xamarin.ios xamarin.forms