简体   繁体   English

在TornadoFX中,如何更改其他属性?

[英]In TornadoFX, how can I make one Property change when other properties are changed?

For example, I want to do this: I have a StringProperty, and it is a combination of an IntegerProperty and anoter StringProperty, like this: 例如,我要这样做:我有一个StringProperty,它是IntegerProperty和注释器StringProperty的组合,如下所示:

  • StringProperty A = "foo" StringProperty A =“ foo”
  • IntegerProperty B = 3 整数属性B = 3
  • resulting StringProperty C = "foo 3" 结果StringProperty C =“ foo 3”

How can I "bind" properties so that the C changes when either A or B are changed? 如何“绑定”属性,以便在更改A或B时更改C? (Note that I don't want to react to changes made to C) (请注意,我不想对C所做的更改做出反应)

I tried using stringBinding() method, but it is unclear to me how this method works exactly, and the documentation about it is unclear. 我尝试使用stringBinding()方法,但是我不清楚此方法的确切工作方式,也不清楚它的文档。

stringBinding is what you want. stringBinding是您想要的。 The first argument will become this inside the calculation block, and if this is an observable value, it will be added as a dependency used to calculate when the string binding should be reevaluated. 第一个参数将在计算块内变为this参数,如果this是一个可观察的值,则将其添加为用于计算何时应重新评估字符串绑定的依赖项。 The rest of the parameters (only b here) are added as re-evaluation dependencies as well. 其余参数(此处仅b )也作为重新评估的依赖项添加。

If you do stringBinding(a, b) { "${a.value} ${b.value}" } , you have created a string binding that will update whenever either a or b changes. 如果执行stringBinding(a, b) { "${a.value} ${b.value}" } ,则创建了一个字符串绑定,该字符串绑定将在ab更改时更新。 Since this is a in the above example, you could also have written in stringBinding(a, b) { "${this.value} ${b.value}" } but I don't think that makes it any clearer :) 由于在上面的示例中thisa ,因此您也可以用stringBinding(a, b) { "${this.value} ${b.value}" }但我认为这没有什么更清楚了:)

The reason we decided to make the first element this is made more apparent by the following example: 究其原因,我们决定以使第一元件this是通过下面的例子中变得更加明确:

val sizeDescription = bind(items) { "$size elements in list" }

Here you don't need to reference the items again to get to it's size property. 在这里,您无需再次引用这些items即可获得它的size属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在TornadoFX中,如何使用objectBinding将BigDecimal属性绑定到另一个BigDecimal属性? - In TornadoFX, how can I bind BigDecimal properites to another BigDecimal property using objectBinding? 如何更改单击的按钮的颜色,但使其只能同时更改一个按钮的颜色? - How can I change the color of a button that is clicked but make it so that only one buttons' color can be changed at the same time? 可以将一个属性值分配给其他属性文件中的另一个属性吗 - Can One property value be assigned to another property in other properties file 当Java中的ListModel更改时,如何更新JList? - How can I make JList update when ListModel changed in java? 当工作流的任务更改某些属性时,如何制定触发策略? - How can I make a policy that trigger when a workflow's task change some property? 当我尝试更新属性文件时,属性文件中的其他值正在更改 - When i try to update properties file, other values in properties file is getting changed 如何在没有一个其他数组的情况下制作一个数组? - How can I make an array without one number of the other array? 如果某些内容被另一类更改,如何使更改对一个类可见? - How to make a change visible to one Class, if something was changed by another Class? 调用时如何使静态属性评估 - How can I make Static Property evalute when called 如何使用hibernate条件查询将两个属性连接到一个属性 - how can i concatenate two properties into one property using hibernate criteria query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM