0

我有一个名为 "CurrencyOne" 的组合框,我写了一个 Linq 查询

 var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
 CurrencyOne.DataContext = curren;

在 xaml 文件中

<ComboBox Name="CurrencyOne"/>

如何确保组合框将填充查询结果?

4

2 回答 2

1

您正在寻找ItemsSource而不是DataContext

var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.ItemsSource = curren;
于 2013-08-19T14:54:36.917 回答
0

您需要设置ItemsSource为应该显示的列表,因此可以直接设置它而不使用DataContext

var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.ItemsSource = curren;

或绑定ItemsSource到当前DataContext

var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.DataContext = curren;

<ComboBox Name="CurrencyOne" ItemsSource="{Binding}"/>
于 2013-08-19T14:53:30.127 回答