有没有办法将 属性 绑定到 tornadofx 中的 appConfig?

Is there any way to bind a property to appConfig in tornadofx?

假设我想在 tornadofx 中使用 appConfig 保存视图的高度和宽度值。有没有办法将这些属性绑定到appConfig,这样当我保存配置时,始终保存最新的高度和宽度值?

如果您想做的是保存 Window 的当前 width/height 并在视图再次停靠时恢复它,您可以覆盖 onDock 以在那里执行两个操作:

override fun onDock() {
    if (config["w"] != null && config["h"] != null) {
        currentWindow?.apply {
            width = config.double("w")!!
            height = config.double("h")!!
        }
    }

    currentWindow?.apply {
        Bindings.add(widthProperty(), heightProperty()).onChange {
            with (config) {
                put("w", width.toString())
                put("h", height.toString())
                save()
            }
        }
    }
}