我有一个名为“CurrencyOne”的组合框,我写了一个Linq查询
var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.DataContext = curren;
和xaml fils
<ComboBox Name="CurrencyOne"/>
如何确保组合框将填充查询结果?
答案 0 :(得分:1)
您正在寻找ItemsSource
而不是DataContext
:
var curren = (from cur in data.MyCurrencys select cur.Value).ToList();
CurrencyOne.ItemsSource = curren;
答案 1 :(得分: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}"/>