![](/img/trans.png)
[英]How to get and display image as byte array from database on Windows Phone 8.1
[英]display image from local folder where image name as source get from sqlite database in windows phone 8 apps
每个人实际上我都在创建Windows Phone8项目。 我在隔离存储中有SQlite数据库文件,该表中有一个名为“ teams”的表,其字段为“ id,team_name”等
我已经插入了团队名称,例如印度,澳大利亚等,并且在我的应用程序本地文件夹中,我有一个具有相同名称的团队图像存储在sqlite DB中,例如india.png,australia.png等。
在我的列表框中,我可以列出所有团队名称和团队图像。,这样我就为
成功从sqlite DB检索数据并显示名称,ID等。
但是,问题是我想显示本地名称为“ country_name”列的国家名称的本地文件夹中的图像,因为
column_name和我的本地图像都具有相同的名称。
我的代码将比我认为的文本更清楚地解释:
我的XAML代码:
<ListBox Name="scheduleListbox" Margin="5,85,5,60" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="100" Width="480" Margin="0,0,0,5" Background="CadetBlue">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Margin="3" Source="{Binding teamUrl}"></Image>
<TextBlock Grid.Column="1" Text="{Binding team1_Name}" Name="team1Name" Foreground="White"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的CS代码是这样的
public partial class Schedule : PhoneApplicationPage
{
List<teams> teamsList;
// the local folder DB path
string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sample.sqlite");
//SQLite connection
private SQLiteConnection dbConn;
dbConn = new SQLiteConnection(DB_PATH);
/// Create the table Task, if it doesn't exist.
dbConn.CreateTable<teams>();
teamsList = dbConn.Query<teams>("select * from teams").ToList<teams>();
// Bind source to listbox
scheduleListbox.ItemsSource =teamsList;
}
public class teams
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string team_Name { get; set; }
}
在这里,我在课堂上声明了对应于teams表列的数据成员,并且无法将team_name分配为图像源
所以,请给我一个解决方案,将team_name设置为图像源,其中团队图像存储在路径(... / images / australia.png)的本地文件夹中
我的要求:最后,我需要从SQLite DB中获取team_name,并使用该team_name作为图像控件的源,以显示本地文件夹本身中的图像。
提前致谢。,
我发现自己可以满足我的要求。我创建了一个名为“ appendList”的类,其中所有现有的数据成员都在“团队”类中,另外的数据成员如teamImage这样
public class teams
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string team_Name { get; set; }
}
public class appendList
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string team_Name { get; set; }
public string teamImage
}
并像这样创建for循环
public partial class Schedule : PhoneApplicationPage
{
List<teams> teamsList;
List<appendList> _appendList;
// the local folder DB path
string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sample.sqlite");
//SQLite connection
private SQLiteConnection dbConn;
dbConn = new SQLiteConnection(DB_PATH);
/// Create the table Task, if it doesn't exist.
dbConn.CreateTable<teams>();
teamsList = dbConn.Query<teams>("select * from teams").ToList<teams>();
//
_appendList=new List<appendList>();
foreach(var t in teamsList)
{
_appendList.add(new appendList
{
teamImage="/..your local image Path/"+t.team_name+".png";
});
}
// Bind source to listbox
scheduleListbox.ItemsSource =_appendList;
}
希望有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.