gpt4 book ai didi

WPF 绑定(bind)集合与索引

转载 作者:行者123 更新时间:2023-12-03 03:47:48 25 4
gpt4 key购买 nike

我正在尝试使用作为另一个集合的属性的集合来绑定(bind)到列表框。以下工作正常

<ListBox ItemsSource="{Binding Path=Locations[0].Buildings}">

问题是我需要一个动态索引

<ListBox ItemsSource="{Binding Path=Locations[index].Buildings}">

其中索引是我的 View 模型中的整数,不起作用。有谁知道如何将 xaml 中的索引与 View 模型中的属性关联起来?

最佳答案

where index is an integer in my viewmodel, does not work. Does anyone know how I can associate the index in my xaml with the property in my viewmodel?

一个简单的选择是在 ViewModel 中公开一个 CurrentLocation 属性,该属性实际上是 Location[index]。然后您可以直接绑定(bind)到它。

关于WPF 绑定(bind)集合与索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16903244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com