简体   繁体   English

显示本地文件夹中的图像,其中图像名称作为来源从Windows Phone 8应用程序中的sqlite数据库获取

[英]display image from local folder where image name as source get from sqlite database in windows phone 8 apps

everybody actually i wm creating windows phone8 project. 每个人实际上我都在创建Windows Phone8项目。 i have SQlite database file in Isolated Storage which is having table called 'teams' with the fieds are " id,team_name" etc 我在隔离存储中有SQlite数据库文件,该表中有一个名为“ teams”的表,其字段为“ id,team_name”等

i have already inserted team name like india,australia etc and also in my application local folder i have a teams images with the same name stored in sqlite DB like india.png,australia.png., etc 我已经插入了团队名称,例如印度,澳大利亚等,并且在我的应用程序本地文件夹中,我有一个具有相同名称的团队图像存储在sqlite DB中,例如india.png,australia.png等。

in my listbox i could list all team name & also team images., so that i have written the code for 在我的列表框中,我可以列出所有团队名称和团队图像。,这样我就为

Retrieving data from sqlite DB and displayed name, id, etc successfully., 成功从sqlite DB检索数据并显示名称,ID等。

But, the problem is i want to display images from local folder where image name comes from country table with the column 'country_name' because 但是,问题是我想显示本地名称为“ country_name”列的国家名称的本地文件夹中的图像,因为

both column_name & my local images have same name., column_name和我的本地图像都具有相同的名称。

my code will explain more clear than text i think: 我的代码将比我认为的文本更清楚地解释:

MY XAML code: 我的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>

and my CS code is Like this 我的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; }
  }

Here in class i declared data member corresponding to teams table columns and cant able to assign team_name as image source 在这里,我在课堂上声明了对应于teams表列的数据成员,并且无法将team_name分配为图像源

so., some one please give me solution to set team_name as source for image where team images are stored in local folder in the path like (.../images/australia.png) 所以,请给我一个解决方案,将team_name设置为图像源,其中团队图像存储在路径(... / images / australia.png)的本地文件夹中

My Requirement : finally my reqiurement is i want to get the team_name from SQLite DB and use this team_name as a source of my image control to display images from my local folder itself., 我的要求:最后,我需要从SQLite DB中获取team_name,并使用该team_name作为图像控件的源,以显示本地文件夹本身中的图像。

Thanks in advance., 提前致谢。,

i found myself answer for my requirements., i have created another one class called "appendList" with all existing data members on class "teams" & extra data member like teamImage like this 我发现自己可以满足我的要求。我创建了一个名为“ 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
     }

and created for loop like this 并像这样创建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;

}

Hope this help., 希望有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Phone 8.1上从数据库获取和显示图像作为字节数组 - How to get and display image as byte array from database on Windows Phone 8.1 Windows Phone 8:从Assets文件夹共享图像 - Windows Phone 8: Share an Image from Assets folder 在 webview 上显示本地文件夹中的文本和图像 - Display Text and Image from local folder on webview 从网页获取图像并显示(Windows Phone) - Get image from Webpage and show (Windows Phone) 如何在Windows Universal App中显示网络文件夹或本地驱动器中的图像 - How to display an image from a network folder or local drive in a Windows Universal App 如何将图像从Filepiker复制到应用程序文件夹Windows存储应用程序 - how to copy image from filepiker to app folder windows store apps 如何从Windows Phone 8.1中的Assets文件夹中获取图像并将其分配给模型的属性 - How to get image from assets folder in windows phone 8.1 and assign it to a model's property Windows Phone 8中使用SQLite的本地数据库 - Local database with SQLite in Windows phone 8 来自Windows窗体(C#)中存储在数据库(sqlite)中的图像路径的datagridview中的图像显示问题 - Image display issue in datagridview from imagepath stored in database(sqlite) in windows form(C#) 如何从URL下载图像并将其保存到本地SQLite数据库 - How to Download Image From Url and Save It to a Local SQLite Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM