将.sdf查询绑定到listbox

本文关键字:listbox 绑定 查询 sdf | 更新日期: 2023-09-27 18:11:34

谁能帮我解决这个问题我想绑定以下结果

 public IList<bankingCategory> bankingInfo()
    {
        IList<bankingCategory> bankList = null;
        using (dataContext context = new dataContext(globalInfo.strConnectionString))
        {
            IQueryable<bankingCategory> query = from c in context.bankcategorees select c;
            bankList = query.ToList();
        }
        return bankList;
    }

将.sdf查询绑定到listbox

set item source from code behind

MyListBox.ItemsSource =bankingInfo();

你需要设置自定义你的列表框模板如下

<Grid>
    <ListBox Name="MyListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Property1}"></TextBlock>
                    <TextBlock Text="{Binding Path=Property2}"></TextBlock>
                </StackPanel>
            </DataTemplate>               
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>