简体   繁体   中英

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. i have SQlite database file in Isolated Storage which is having table called 'teams' with the fieds are " id,team_name" etc

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

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.,

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

both column_name & my local images have same name.,

my code will explain more clear than text i think:

MY XAML code:

   <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

  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

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)

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.,

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

    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

      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.,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM