【问题标题】:Is there any way to bind a property to appConfig in tornadofx?有没有办法将属性绑定到 tornadofx 中的 appConfig?
【发布时间】:2017-09-15 12:14:02
【问题描述】:

假设我想在 tornadofx 中使用 appConfig 保存视图的高度和宽度值。无论如何我可以将这些属性绑定到appConfig,这样当我保存配置时,总是会保存最新的高度和宽度值?

【问题讨论】:

    标签: kotlin tornadofx


    【解决方案1】:

    如果您要做的是保存 Window 的当前宽度/高度并在 View 再次停靠时恢复它,您可以覆盖 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()
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      • 2012-07-07
      • 2010-12-19
      • 1970-01-01
      相关资源
      最近更新 更多