【发布时间】:2020-04-27 13:06:36
【问题描述】:
在 XAML 中的 Xamarin.Forms 中,您可以编写如下内容:
<Entry Keyboard="Plain" />
我发现了 Entry 类,Keyboard 属性的类型是 Xamarin.Forms.Keyboard。但是,如果我创建自己的自定义 ContentView 并在里面写这样的内容:
public static readonly BindableProperty KeyboardProperty = BindableProperty.Create
(
propertyName: "Keyboard",
returnType: typeof(Keyboard),
declaringType: typeof(MyCustomContentView),
defaultValue: Keyboard.Default,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) =>
{
// some unrelated stuff here
}
);
public Keyboard Keyboard
{
get => (Keyboard)GetValue(KeyboardProperty);
set => SetValue(KeyboardProperty, value);
}
我不能为我自己的内容视图使用相同的 XAML 格式。显然它是一个简单的字符串,它期望Xamarin.Forms.Keyboard 类的实例。到目前为止,我发现它与KeyboardProperty 或绑定无关,而是Keyboard 属性本身(如果我是正确的)。我相信它与ValueConverters 有关,当 XAML 解析器到达这部分时,我必须定义某种形式的字符串到键盘的转换,只是似乎无法找到我需要做的答案。
【问题讨论】:
标签: c# xaml xamarin.forms converters