我有一个名为 "CurrencyOne" 的组合框,我写了一个 Linq 查询
var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.DataContext = curren;
在 xaml 文件中
<ComboBox Name="CurrencyOne"/>
如何确保组合框将填充查询结果?
我有一个名为 "CurrencyOne" 的组合框,我写了一个 Linq 查询
var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.DataContext = curren;
在 xaml 文件中
<ComboBox Name="CurrencyOne"/>
如何确保组合框将填充查询结果?
您正在寻找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.ItemsSource = curren;
或绑定ItemsSource
到当前DataContext
:
var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.DataContext = curren;
<ComboBox Name="CurrencyOne" ItemsSource="{Binding}"/>