将 ListView 绑定到 ListProperty
Bind ListView to ListProperty
在 tornadoFX 中是否可以将 ListView 绑定到 ListProperty?
我有一个如下所示的 ViewModel:
class MyVm: ItemViewModel<Item>() {
val stringProperty = bind { item?.myString?.toProperty() }
}
class MyView: View() {
...
init {
with (root) {
label(myVm.stringProperty)
}
}
}
如果项目随 vm.item = Item(...)
发生变化,则 stringProperty 将相应更新,这将更新所有绑定标签等...
现在我想对 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
将您的绑定定义为 ListProperty 并将 listProperty 传递给列表视图构建器:
val listProperty = bind(Item::myList) as ListProperty<YourType>
..
listview(myVm.listProperty)
在 tornadoFX 中是否可以将 ListView 绑定到 ListProperty?
我有一个如下所示的 ViewModel:
class MyVm: ItemViewModel<Item>() {
val stringProperty = bind { item?.myString?.toProperty() }
}
class MyView: View() {
...
init {
with (root) {
label(myVm.stringProperty)
}
}
}
如果项目随 vm.item = Item(...)
发生变化,则 stringProperty 将相应更新,这将更新所有绑定标签等...
现在我想对 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
将您的绑定定义为 ListProperty 并将 listProperty 传递给列表视图构建器:
val listProperty = bind(Item::myList) as ListProperty<YourType>
..
listview(myVm.listProperty)