在Windows Phone的选择SQLite数据库到列表框项目数据和绑定值8应用 [英] select data from sqlite database and binding values to listbox item in windows phone 8 apps

查看:98
本文介绍了在Windows Phone的选择SQLite数据库到列表框项目数据和绑定值8应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用数据库中创建的Windows Phone 8的项目(源码)技术

I am trying to creating windows phone 8 project with database (sqlite) techniques

我曾尝试以下内容:

1)服务器&安培下载sqlite的外商投资企业;在本地应用程序保存它

1) Download sqlite fie from server & saved it in local app

2)我也可以检索从本地SQLite数据库的值,通过使用的这个链接&安培;一些其他的环节了。

2) I can also retrieve the values from local sqlite database and displayed in message box by using some sample codes from This Link & some other links too.

不过,我不能够绑定的值列表框。

But, I am not able to bind that values in listbox.

下面是我的代码:

XAML代码:

   <Grid x:Name="ContentPanel" Grid.RowSpan="2">
        <ListBox Name="scheduleListbox" Margin="5,85,5,60" ItemsSource="{Binding}" SelectionChanged="scheduleListbox_SelectionChanged">
             <ListBox.ItemTemplate>
                <DataTemplate>
                <Grid Height="250" Width="480">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20"></RowDefinition>
                        <RowDefinition Height="40"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                        <RowDefinition Height="40"></RowDefinition>
                    </Grid.RowDefinitions>
                    <TextBlock Name="team1Name" Text="{Binding team1_name}" Grid.Row="0"></TextBlock>
                    <TextBlock Name="team2Name" Text="{Binding team2_name}"></TextBlock>
                    <TextBlock Name="venue" Text="{Binding venue}" ></TextBlock>
                </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <toolkit:ListPicker Name="selectTeam" Height="60" ItemsSource="{Binding}" VerticalAlignment="Bottom" Background="Black" FullModeHeader="Select your Team Schedule" Foreground="White" ExpansionMode="FullScreenOnly" Margin="5,0" SelectionChanged="selectTeam_SelectionChanged">
            <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <StackPanel Name="listpickerStackpannel" >
                        <TextBlock Text="{Binding}" TextAlignment="Center" FontFamily="Times New Roman" FontSize="30"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Name="listpickerStackpannel" Margin="10">
                        <TextBlock Text="{Binding}" TextAlignment="Center" FontFamily="Times New Roman" FontSize="30"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
        </toolkit:ListPicker>
    </Grid>

和我的CS代码是:

     string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sample.sqlite");
    //SQLite connection
    private SQLiteConnection dbConn;
    private List<string> _source = new List<string>
    {
        "Full Schedule","Afghanistan","Australia","Bangladesh","England","Hong Kong","India","Ireland","Nepal","Netherlands","New Zealand","Pakistan","South Africa","Sri Lanka","UAE","West Indies","Zimbabwe"
    };
    public MainPage1()
    {
        InitializeComponent();
        selectTeam.ItemsSource = _source;
    }

    private void scheduleListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        dbConn = new SQLiteConnection(DB_PATH);
        /// Create the table Task, if it doesn't exist.
        dbConn.CreateTable<iccworldt20_schedule>();
        /// Retrieve the task list from the database.
        List<iccworldt20_schedule> retrievedTasks = dbConn.Query<iccworldt20_schedule>("select * from iccworldt20_schedule").ToList<iccworldt20_schedule>();
        /// Clear the list box that will show all the tasks.
        scheduleListbox.Items.Clear();
        foreach (var t in retrievedTasks)
        {
            MessageBox.Show(t.ToString());
        }
    }
}
public class iccworldt20_schedule
{
    [PrimaryKey, AutoIncrement]
    public int match_id { get; set; }
    public string team1_Name { get; set; }
    public string team2_Name { get; set; }
    public string match_no { get; set; }
    public string group { get; set; }
    public string venue { get; set; }
    public string time { get; set; }
    public string day { get; set; }

    public override string ToString()
    {
        return team1_Name + ":" + team2_Name +venue;
    }
}

请给一些解决方案,如何从sqlite的值DB和约束其值列表框。

Please give some solution that how to retrieve values from sqlite DB and bind its values to listbox.,

推荐答案

我看不到你在哪里将数据添加到一个列表框的任何代码。如果你有从数据库中抽取数据,将其添加到ItemsSource属性这一切

I can't see any code where you are adding data to a ListBox. If you have data pulled from the database, add it to ItemsSource property that's all.

scheduleListbox.ItemsSource = retrievedTasks;



我不明白为什么您使用的ItemsSource =上selectTeam ListPicker{结合}时填写它在构造函数中。你们为什么用同样以scheduleListbox。见

如果您有忧色空绑定语法:{}绑定。列表框继承父元素DataContext的。如果未指定路径,则默认为绑定到整个对象。

If you youse empty binding syntax: {Binding}. The ListBox inherits the DataContext from a parent element. When the path is not specified, the default is to bind to the entire object.

这篇关于在Windows Phone的选择SQLite数据库到列表框项目数据和绑定值8应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆