斯卡拉外汇。 Label - 如何绑定 IntegerProperty?
ScalaFX. Label - How to bind IntegerProperty?
我有一个简单的表格例如:
object Main extends JFXApp {
stage = new PrimaryStage() {
title = "My Form"
scene = new Scene {
root = new Label { text <== ViewModel.intProp }
}
}
}
还有一个简单的 ViewModel 示例:
object ViewModel {
//Some mutable integer property. I want to keep it as IntegerProperty, not StringProperty
val intProp = IntegerProperty(10)
intProp.value = 15
}
如何将我的 IntegerProperty
绑定到需要 StringProperty
的标签?
已编辑:我忘记了 .asString
。呸!
您可以简单地绑定 属性 如下:
Main.scala
:
object Main extends JFXApp {
stage = new PrimaryStage() {
title = "My Form"
scene = new Scene {
// Bind label to int property as a string.
root = new Label {
text <== ViewModel.intProp.asString
}
}
}
}
ViewModel.scala
:
object ViewModel {
val intProp = IntegerProperty(10)
intProp.value = 15
}
我有一个简单的表格例如:
object Main extends JFXApp {
stage = new PrimaryStage() {
title = "My Form"
scene = new Scene {
root = new Label { text <== ViewModel.intProp }
}
}
}
还有一个简单的 ViewModel 示例:
object ViewModel {
//Some mutable integer property. I want to keep it as IntegerProperty, not StringProperty
val intProp = IntegerProperty(10)
intProp.value = 15
}
如何将我的 IntegerProperty
绑定到需要 StringProperty
的标签?
已编辑:我忘记了 .asString
。呸!
您可以简单地绑定 属性 如下:
Main.scala
:
object Main extends JFXApp {
stage = new PrimaryStage() {
title = "My Form"
scene = new Scene {
// Bind label to int property as a string.
root = new Label {
text <== ViewModel.intProp.asString
}
}
}
}
ViewModel.scala
:
object ViewModel {
val intProp = IntegerProperty(10)
intProp.value = 15
}