delphi - 使用实时绑定(bind)将多个字段值分配给 FMX MetropolisUI TListBox Item.Text

标签 delphi microsoft-metro firemonkey livebindings tlistbox

我正在编写一个 FMX Metropolis UI 应用程序,并尝试通过 LiveBindings 技术(使用表达式引擎)将两个字符串类型的字段值分配给 TListBox 的 Item.Title 成员。

当我按以下方式使用 TBindList 时:

object BindList1: TBindList
  Category = 'Lists'
  ControlComponent = ListBox1
  SourceComponent = BindSourceDB1
  FormatExpressions = <
    item
      ControlExpression = 'Text'
      SourceExpression =
        'FieldByName("name1").Text + " " + Field' +
        'ByName("name2").Text'
    end>
  FormatControlExpressions = <>
  ClearControlExpressions = <>
end 

它将“name1 name2”字符串分配给成员 Text但我无法设置 ListItemStyle := MetropolisUI因为 TBindList 类中没有这样的属性

如果我使用TLinkFillControlToField

object LinkFillControlToField2: TLinkFillControlToField
      Category = 'Quick Bindings'
      Control = ListBox1
      Track = True
      FillDataSource = BindSourceDB1
      FillDisplayFieldName = 'name1'
      AutoFill = True
      BufferCount = -1
      AutoBufferCount = False
      FillExpressions = <>
      FillHeaderExpressions = <>
      FillBreakGroups = <>
    end

它让我分配 ListItemStyleMetropolisUI ,但我只能使用 FillDisplayFieldName 访问一个字段属性(property)并没有SourceExpression要分配的字段 'FieldByName("name1").Text + " " + FieldByName("name2").Text'到它。

我试图猜测 Item.Text 的上下文TListBox的成员来自TBindList但我没能做到。我研究了 Delphi 示例,但没有 Metropolis TListBox,而且它的行为方式似乎与常见的不同。有人知道如何找到此问题的解决方案吗?

最佳答案

感谢 @house-of-dexter 的帖子,他给了 answer关于TLabel这鼓励我尝试TLinkFillControlToField再次。主要问题是字段名的上下文可以在 Self.Owner 中找到。 .

object LinkFillControlToField2: TLinkFillControlToField
  Category = 'Quick Bindings'
  DataSource = BindSourceDB1
  Control = ListBox1
  Track = True
  FillDataSource = BindSourceDB1
  AutoFill = True
  BufferCount = -1
  AutoBufferCount = False
  ListItemStyle = 'MetropolisUI'
  FillExpressions = <
    item
      SourceMemberName = 'name1'
      ControlMemberName = 'Title'
      CustomFormat = 'Self.Owner.name1.text+" "+Self.Owner.name2.text'
    end>
  FillHeaderExpressions = <>
  FillBreakGroups = <>
end

关于delphi - 使用实时绑定(bind)将多个字段值分配给 FMX MetropolisUI TListBox Item.Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31202376/

相关文章:

delphi - 创建自定义表单设计器

delphi - 编写/读取Windows注册表-Windows服务

c# - CoreWindow.GetForCurrentThread().SizeChanged 和 Window.Current.SizeChanged 事件有什么区别

delphi - 如何在 VCL 项目上获取 Fmx 项目中的 Windows 关闭事件作为 WM_QUERYENDSESSION 和 WM_ENDSESSION ?

Delphi FMX 验证 EditText 是否仅包含数字?

delphi - 如何创建一个可与 VCL 和 FMX 一起使用的内部计时器?

delphi - Delphi中如何区分多个键盘?

delphi - 透明TCustomControl?

windows - 使用 CSS3、HTML5 和 Javascript 重新创建 WP7 Metro UI 的外观

windows-phone-7 - Windows 8 Metro Style 类与 Windows Phone 7 DeviceStatus 类的等效项是什么?