问题描述
<cv:BindableComboBox ItemsSource="{Binding Themes}" SelectedValue="{Binding SelectedTheme}">
<cv:BindableComboBox.Title>
<OnPlatform x:TypeArguments="x:String"
iOS="{Binding ThemePickerTitle}"
Android="{Binding ThemePickerTitle}"/>
</cv:BindableComboBox.Title>
</cv:BindableComboBox>
所以我有选择器,我想将其Title绑定到ThemePickerTitle属性.如果我将其写为inline attrubute,它会很好地工作.但是我不想在Windows上有标题.因此,我编写OnPlatform使其仅在Ios和Droid上具有,但现在可以编译了.
so I have picker and I want to bind its Title to ThemePickerTitle property.It works well if I write it as inline attrubute. But I dont want to have title on windows. So I write OnPlatform to have it only on Ios and Droid, but now it does compile.
推荐答案
您粘贴的Xaml假定 OnPlatform
对象是Binding to string的目标,然后OnPlatform返回正确的 string
(取决于平台).
The Xaml you pasted suppose that the OnPlatform
object is the target of the Binding to string, and then the OnPlatform returns the right string
depending on the Platform.
不幸的是,这不起作用,因为 OnPlatform
不是 BindableObject
,并且不能成为 Binding
的目标.
Unfortunately, that doesn't work because OnPlatform
is not a BindableObject
and can't be the target of a Binding
.
有意义的是,正在使用此Xaml:
What make sense, is using this Xaml:
<cv:BindableComboBox ItemsSource="{Binding Themes}" SelectedValue="{Binding SelectedTheme}">
<cv:BindableComboBox.Title>
<OnPlatform x:TypeArguments="BindingBase"
iOS="{Binding ThemePickerTitle}"
Android="{Binding ThemePickerTitle}"/>
</cv:BindableComboBox.Title>
</cv:BindableComboBox>
这意味着 OnPlatform
根据平台返回正确的Binding(不评估它).截至今天(2017-01-24),这在Xamarin.Forms中不起作用,但已修复的补丁已发布,将在下一版本中发布: https://github.com/xamarin/Xamarin.Forms/pull/709 .
It means that the OnPlatform
returns the right Binding (without evaluating it) depending on the platform. As of today (2017-01-24), this does not work in Xamarin.Forms, but the patch to fix that is ready and will land in one of the next version: https://github.com/xamarin/Xamarin.Forms/pull/709.
这篇关于xamarin形式xaml OnPlatform不适用于绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!