将.sdf查询绑定到列表框

时间:2013-04-30 11:00:48

标签: c# windows-phone-7 windows-phone-8 sql-server-ce

任何人都可以帮我解决这个问题,我想绑定以下结果。

 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;

    }

1 个答案:

答案 0 :(得分:1)

从后面的代码设置项目源

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>