簡體   English   中英

顯示本地文件夾中的圖像,其中圖像名稱作為來源從Windows Phone 8應用程序中的sqlite數據庫獲取

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM