2014-10-30 94 views
0

我想在我的相应页面横向显示从数据库中6个值,例如 日期|时间|地板|专区|纬度|经度 但页面只显示 数据|时间|地板|区 并没有显示经纬度 下面是我的XAML代码的XAML的Windows手机8

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <!--TitlePanel contains the name of the application and page title--> 
    <StackPanel Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock Text="Smart Parking" Style="{StaticResource PhoneTextNormalStyle}"/> 
     <TextBlock Text="History" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 
    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <ListBox x:Name="ListData"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
          <StackPanel Orientation="Horizontal"> 
          <TextBlock x:Name= "DateTxt" Text="{Binding Date}" TextWrapping="Wrap" /> 
          <TextBlock x:Name= "TimeTxt" Text="{Binding Time}" TextWrapping="Wrap" /> 
          <TextBlock x:Name= "ZoneTxt" Text="{Binding Zone}" TextWrapping="Wrap"/> 
          <TextBlock x:Name= "FloorTxt" Text="{Binding Floor}" TextWrapping="Wrap"/> 
          <TextBlock x:Name= "LatTxt" Text="{Binding location_latitude}" TextWrapping="Wrap" /> 
          <TextBlock x:Name= "LongTxt" Text="{Binding location_longitude}" TextWrapping="Wrap" /> 
         </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
    </Grid> 
</Grid> 

谁能帮我改进或纠正呢?

的列表itmesource背后的代码是在这里下面

public partial class History : PhoneApplicationPage 
{ 





    // string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite"); 
    ObservableCollection<historyTableSQlite> DB_HistoryList = new ObservableCollection<historyTableSQlite>(); 
    DbHelper add = new DbHelper(); 
    public History() 
    { 

     InitializeComponent(); 

    } 

    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     add.AddInfo(); 
     ReadHistoryList_Loaded(); 
    } 

    public void ReadHistoryList_Loaded() 
    { 
     ReadAllContactsList dbhistory = new ReadAllContactsList(); 
     DB_HistoryList = dbhistory.GetAllHistory();//Get all DB contacts 
     ListData.ItemsSource = DB_HistoryList.OrderByDescending(i => i.Id).ToList();//Latest contact ID can Display first 

    } 

这里下面是所有主要功能

public class DbHelper 
{ 

    SQLiteConnection dbConn; 

    public async Task<bool> onCreate(string DB_PATH) 
    { 
     try 
     { 
      if (!CheckFileExists(DB_PATH).Result) 
      { 
       using (dbConn = new SQLiteConnection(DB_PATH)) 
       { 
        dbConn.CreateTable<historyTableSQlite>(); 
       } 
      } 
      return true; 
     } 
     catch 
     { 
      return false; 
     } 
    } 


    private async Task<bool> CheckFileExists(string fileName) 
    { 
     try 
     { 
      var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName); 
      return true; 
     } 
     catch 
     { 
      return false; 
     } 
    } 

    //retrieve all list from the database 
    public ObservableCollection<historyTableSQlite> ReadHistory() 
    { 
     using (var dbConn = new SQLiteConnection(App.DB_PATH)) 
     { 
      List<historyTableSQlite> myCollection = dbConn.Table<historyTableSQlite>().ToList<historyTableSQlite>(); 
      ObservableCollection<historyTableSQlite> HistoryList = new ObservableCollection<historyTableSQlite>(myCollection); 
      return HistoryList; 
     } 
    } 

    // Insert the new info in the histrorytablesqlite table. 
    public void Insert(historyTableSQlite newcontact) 
    { 
     using (var dbConn = new SQLiteConnection(App.DB_PATH)) 
     { 
      dbConn.RunInTransaction(() => 
      { 
       dbConn.Insert(newcontact); 
      }); 
     } 
    } 

    public void AddInfo() 
    { 

     DbHelper Db_helper = new DbHelper(); 
     Db_helper.Insert((new historyTableSQlite 
     { 
      Date = DateTime.Now.ToShortDateString(), 
      Time = DateTime.Now.ToShortTimeString(), 
      Zone = "PST", 
      Floor = "10th Floor", 
      latitude = 35.45112, 
      longtitude = -115.42622 
     })); 

    } 


} 

和最后一堂课DBhelper类保持值

public class historyTableSQlite : INotifyPropertyChanged 
{ 
    [SQLite.PrimaryKey, SQLite.AutoIncrement] 

    public int Id { get; set; } 
    private int idvalue; 

    private string dateValue = string.Empty; 

    public string Date { 
     get { return this.dateValue; } 
     set 
     { 
      if (value != this.dateValue) 
      { 
       this.dateValue = value; 
       NotifyPropertyChanged("Date"); 
      } 
     } 
    } 


    private string timeValue = string.Empty; 
    public string Time 
    { 
     get { return this.timeValue; } 
     set 
     { 
      if (value != this.timeValue) 
      { 
       this.timeValue = value; 
       NotifyPropertyChanged("Time"); 
      } 
     } 
    } 

    private string floorValue = string.Empty; 
    public string Floor 
    { 
     get { return this.floorValue; } 
     set 
     { 
      if (value != this.floorValue) 
      { 
       this.floorValue = value; 
       NotifyPropertyChanged("Floor"); 
      } 
     } 
    } 

    public string zoneValue; 
    public string Zone 
    { 
     get { return this.zoneValue; } 
     set 
     { 
      if (value != this.zoneValue) 
      { 
       this.zoneValue = value; 
       NotifyPropertyChanged("Zone"); 
      } 
     } 
    } 

    private double latValue; 
    public double latitude 
    { 
     get { return latValue; } 
     set 
     { 
      if (value != this.latValue) 
      { 
       this.latValue = value; 
       NotifyPropertyChanged("Latitude"); 
      } 
     } 
    } 

    private double lonValue; 
    public double longtitude 
    { 
     get { return this.lonValue; } 
     set 
     { 
      if (value != this.lonValue) 
      { 
       this.lonValue = value; 
       NotifyPropertyChanged("Longitude"); 
      } 
     } 
    } 

    // public string isMarkPoint { get; set; } 

    public historyTableSQlite() 
    { 

    } 

    public historyTableSQlite(string date,string time,string floor,string zone,double lat,double lng) 
    { 
     Date = date; 
     Time = time; 
     Floor = floor; 
     Zone = zone; 
     latitude = lat; 
     longtitude = lng; 
    } 
    public event PropertyChangedEventHandler PropertyChanged; 

    private void NotifyPropertyChanged(String info) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(info)); 
     } 
    } 
} 
+0

什么是ListData.ItemsSource设置为?你可以在后面显示代码吗? – bit 2014-10-30 08:33:34

+0

@bit是我按照您的要求更新了以上代码。感谢您查看我的代码 – 2014-10-30 08:41:48

回答

0

您正在将您的文本块绑定到location_longitude,但我没有看到任何位置_经度(或纬度)在你的代码后面。

另外,你有一点点的拼写错误在你LongitudeLatitude声明

public double longtitude // Here change to Longitude 
    { 
     get { return this.lonValue; } 
     set 
     { 
      if (value != this.lonValue) 
      { 
       this.lonValue = value; 
       NotifyPropertyChanged("Longitude"); 
      } 
     } 
    } 

private double latValue; 
    public double latitude // Change to Latitude 
    { 
     get { return latValue; } 
     set 
     { 
      if (value != this.latValue) 
      { 
       this.latValue = value; 
       NotifyPropertyChanged("Latitude"); 
      } 
     } 
    } 

试图将文本块绑定为

<TextBlock x:Name="LatTxt" Text="{Binding Latitude}" TextWrapping="Wrap" /> 
<TextBlock x:Name="LongTxt" Text="{Binding Longitude}" TextWrapping="Wrap" /> 

希望这有助于。

+1

纬度相同。属性名称必须与NotifyPropertyChanged的参数相同,即大写字母“Latitude”。 – Clemens 2014-10-30 08:51:00

+0

是的,我相应地更新了代码,我会更新句子以确保它的精确性。 – Aymeric 2014-10-30 08:52:48

+0

@America非常感谢。有效! – 2014-10-30 08:58:01