【发布时间】:2018-01-10 00:30:26
【问题描述】:
考虑以下示例:
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 }
}
}
如何根据someBooleanProperty 动态更改borderpane 的背景颜色(例如true 时为红色,false 时为绿色)?是否有可能将 CSS 类绑定到属性?有没有不使用 CSS 的解决方案(意思是 style 块等)
【问题讨论】: