【问题标题】:xamarin forms xaml OnPlatform not working on bindingsxamarin 形成 xaml OnPlatform 无法处理绑定
【发布时间】:2017-06-05 06:10:09
【问题描述】:
    <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>

所以我有选择器,我想将它的标题绑定到 ThemePickerTitle 属性。 如果我将它写为内联属性,它会很好地工作。但我不想在 Windows 上有标题。所以我写了 OnPlatform 让它只在 Ios 和 Droid 上运行,但现在它可以编译了。

【问题讨论】:

  • 我觉得typeArgument应该不一样,但是不知道应该是什么

标签: c# xaml xamarin binding xamarin.forms


【解决方案1】:

您粘贴的 Xaml 假设 OnPlatform 对象是 Binding to string 的目标,然后 OnPlatform 根据平台返回正确的 string

很遗憾,这不起作用,因为 OnPlatform 不是 BindableObject 并且不能成为 Binding 的目标。

有意义的是,使用这个 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 根据平台返回正确的绑定(不评估它)。截至今天(2017 年 1 月 24 日),这在 Xamarin.Forms 中不起作用,但要修复的补丁已经准备好并将在下一个版本中登陆:https://github.com/xamarin/Xamarin.Forms/pull/709

【讨论】:

  • 非常感谢
猜你喜欢
  • 2017-02-09
  • 2015-04-14
  • 2017-12-14
  • 1970-01-01
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 2021-06-05
相关资源
最近更新 更多