我见过“x:Static”表达式的示例,用于指定WPF XAML中绑定的ConverterParameter属性。但是,据我所知,Xamarin不允许您以这种方式设置属性。在后面的代码中指定ConverterParameter工作正常,使用StaticResource表达式工作正常,使用文字值,很好。有人可以指点我在Xamarin做一个这样的例子吗?
我的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"
x:Class="OMS.ProductionPickupPage"
xmlns:local="clr-namespace:OMS;assembly=OMS"
Title="Production Pickup"
Padding="5,5,5,5">
<ContentPage.Resources>
<ResourceDictionary>
<local:PickerIndexConverter x:Key="PickerConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<!-- ... -->
<Picker x:Name="LoadingFacility_Picker" Title="Loading Facility" SelectedIndex="{Binding SelectedLoadingFacility, Mode=OneWayToSource,
Converter={StaticResource PickerConverter}, ConverterParameter={x:Static local:TestClass.TestMember}}" />
这是InitializeComponent()中LoadFromXml方法抛出的异常:
System.Exception: Property is not valid for this Expression
堆栈追踪:
[External Code]
0xC in OMS.ProductionPickupPage.InitializeComponent at e:\Workspace\sumrallj\OMS\OMS\OMS\obj\Debug\ProductionPickupPage.xaml.g.cs:42,-1 C#
0x14 in OMS.ProductionPickupPage..ctor at e:\Workspace\sumrallj\OMS\OMS\OMS\ProductionPickupPage.xaml.cs:17,-1 C#
0x1 in OMS.App.GetMainPage at e:\Workspace\sumrallj\OMS\OMS\OMS\App.cs:14,-1 C#
0x22 in OMS.iOS.AppDelegate.FinishedLaunching at e:\Workspace\sumrallj\OMS\OMS\OMS.iOS\AppDelegate.cs:34,-1 C#
0xB in MonoTouch.UIKit.UIApplication.Main at /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62,4 C#
0x3B in MonoTouch.UIKit.UIApplication.Main at /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46,4 C#
0x8 in OMS.iOS.Application.Main at e:\Workspace\sumrallj\OMS\OMS\OMS.iOS\Main.cs:17,-1 C#
TestClass和TestMember都是静态的,我也尝试使用枚举。
namespace OMS
{
public static class TestClass
{
public static string TestMember = "Test";
}
}