gpt4 book ai didi

c# - 绑定(bind) List 到 ComboBox

转载 作者:可可西里 更新时间:2023-11-01 08:42:08 24 4
gpt4 key购买 nike

我希望从我的列表中获取我的组合框项目名称和值当然,我不希望我的 View 模型包含组合框项目列表。

我得到了一个列表a,b,c,d

我希望我的组合框有项目

我的 View 模型得到了

public List<string> PropsList { get; set; }

我的观点得到了

<ComboBox Name="cbPropName" ItemsSource="PropsList"/>

它给了我与 P r o p s L i s t 组合

:(

最佳答案

Nahum 你将不得不使用 ItemsSource="{Binding PropsList}",假设 PropsList 是你代码背后的一个依赖属性,或者更好的是,你的数据上下文中的一个属性实现了 INotifyPropertyChanged。在您的情况下,您必须将 View 的 DataContext 属性设置为 ViewModel

关于c# - 绑定(bind) List<string> 到 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7329577/

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