将ListView绑定到ListProperty [英] Bind ListView to ListProperty

查看:120
本文介绍了将ListView绑定到ListProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tornadoFX是否可以将ListView绑定到ListProperty?

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

我有一个如下的ViewModel:

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)
        }
    }
}

如果项目更改为vm.item = Item(...),则stringProperty将相应地更新,这将更新所有绑定的标签等.

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

现在我要对ListView做同样的事情:

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
            }
        }
    }
}

但是在这种情况下,编译器会抱怨listview.items期望使用ObservableList而不是ListProperty

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

推荐答案

将绑定定义为ListProperty并将listProperty传递给listview构建器:

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)

这篇关于将ListView绑定到ListProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆