将字典升级为网格

时间:2014-05-14 07:56:29

标签: c# sql-server xaml windows-phone-8 grid

我第一次使用Windows phone 8应用程序,我对控件和术语并不熟悉,所以请原谅我。

我有一个Windows Phone 8应用程序需要显示书籍列表,即:以列表格式显示书名和书籍。

我已经为项目使用了Windows phone DataBoundApp模板。我试图将网格与数据库值绑定。

这是我的代码:

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            using(Context c=new Context(Context.ConnectionString))
            {
                c.LogDebug = true;

                char[] allchar = new char[4] { 'A', 'B','C','D' };

                List<DB.Books> keys = new List<DB.Books>();

                var exampleDictionary = new Dictionary<List<DB.Books>, string>();
                for (int i = 0; i <= 3; i++)
                {

                    var book = from m in c.Books
                               where m.Book_author.StartsWith(allchar[i].ToString())
                                orderby Convert.ToChar(m.Book_author)
                              select m;


                    keys.AddRange(book.ToList());

                    exampleDictionary.Add(book.ToList(), allchar[i].ToString());

                }
                MainLongListSelector.ItemsSource = exampleDictionary.ToList();

            }

        }

和Xaml来源:

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="MainLongListSelector_SelectionChanged">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>

                        <StackPanel Margin="0,0,0,17">

                            <TextBlock Text="{Binding Path=Value}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" Grid.Column="1"/>
                            <TextBlock Text="{Binding Path=Key[1].Book_author}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" Grid.Column="2"/>
                           </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>
        </Grid>

这里我试图按字母顺序列出书籍,所以设计应该如下:

A:
book1-title,book1-desc
book2-title,book2-desc
book3-title,book3-desc
B:
book1-title,book1-desc
book2-title,book2-desc
book3-title,book3-desc
...

请帮帮我。提前谢谢。

0 个答案:

没有答案