TornadoFX bind ListView to ListProperty

人走茶凉 提交于 2019-12-11 01:12:17

问题


Is it possible in tornadoFX to bind a ListView to a ListProperty?

I have a ViewModel like follows:

class MyVm: ItemViewModel<Item>() {
    val stringProperty = bind { item?.myString?.toProperty() }
}

class MyView: View() {
    ...
    init {
        with (root) {
            label(myVm.stringProperty)
        }
    }
}

if the item changes with vm.item = Item(...) the stringProperty will be updated accordingly, which will update all bound labels etc...

Now I want to do the same with a ListView:

class MyVm: ItemViewModel<Item>() {
    val listProperty = bind { item?.myList?.toProperty() }
}

class MyView: View() {
    ...
    init {
        with (root) {
            listview {
                items = myVm.listProperty
            }
        }
    }
}

But in this case the compiler complains that listview.items expects an ObservableList instead of a ListProperty


回答1:


Define your binding as a ListProperty and pass the listProperty to the listview builder:

val listProperty = bind(Item::myList) as ListProperty<YourType>

..

listview(myVm.listProperty)



来源:https://stackoverflow.com/questions/50260206/tornadofx-bind-listview-to-listproperty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!