将List <string>绑定到ComboBox

Nah*_*hum 11 c# wpf binding mvvm

我希望我的组合框项目名称和值可以从我的列表中获取当然我不希望我的视图模型保存组合框项目列表.

我有一份清单 a,b,c,d

我希望我的组合框有物品

我的观点模型了

public List<string> PropsList { get; set; }
Run Code Online (Sandbox Code Playgroud)

我的观点得到了

<ComboBox Name="cbPropName" ItemsSource="PropsList"/>
Run Code Online (Sandbox Code Playgroud)

它给了我与P rops L ist的组合

:(

Ami*_*ira 13

Nahum你必须使用ItemsSource="{Binding PropsList}",假设PropsList是你的代码背后的Dependancy属性,或者更好的是,你的数据上下文中的属性实现INotifyPropertyChanged.在您的情况下,您必须将DataContextView 的属性设置为ViewModel