考虑以下示例:
class MainView : View("Example") {
val someBooleanProperty: SimpleBooleanProperty = SimpleBooleanProperty(true)
override val root = borderpane {
paddingAll = 20.0
center = button("Change bg color") {
action {
// let's assume that new someBooleanProperty value is updated
// from some API after button clicked
// so changing style of the borderpane in action block
// of the button is not the solution
someBooleanProperty.value = !someBooleanProperty.value
}
}
}
}
class Styles : Stylesheet() {
companion object {
val red by cssclass()
val green by cssclass()
}
init {
red { backgroundColor += Color.RED }
green { backgroundColor += Color.GREEN }
}
}
如何动态更改borderpane
取决于someBooleanProperty
(例如 RED whentrue
和 GREEN when false
)的背景颜色?是否有可能将 CSS 类绑定到属性?是否有任何解决方案可以在不使用 CSS 的情况下做到这一点(意思是在style
块内等)