2011-07-26 63 views
0

可能重複:
Grid in windows phone 7電網中的Windows Phone 7

我想鴻溝一個名爲 「scheduleListBox」 網格成2列,然後將時間在變量「時間」和下一列放置一個按鈕它。

以下是我的代碼:

string selectedFolderName;

string selectedFolderName1; 
    string[] timeSplit; 
    string timeSaved; 
    string timeList; 
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     base.OnNavigatedTo(e); 
     selectedFolderName = ""; 
     if (NavigationContext.QueryString.TryGetValue("selectedFolderName", out selectedFolderName)) 
      selectedFolderName1 = selectedFolderName; 


     IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
     StreamReader readFile = new StreamReader(new IsolatedStorageFileStream(selectedFolderName1 + "\\time.Schedule", FileMode.Open, myStore)); 

     String timeText = readFile.ReadLine(); 
     timeSplit = timeText.Split(new char[] { '^' }); 


     foreach (var time in timeSplit) 
     { 
      timeList = time; 
      MessageBox.Show("time " + timeList); 




      //Define grid column, size 
      Grid schedule = new Grid(); 
      ColumnDefinition scheduleTitleColumn = new ColumnDefinition(); 
      //grid1 to hold the label of the alarm 
      GridLength titleGrid = new GridLength(320); 
      scheduleTitleColumn.Width = titleGrid; 
      schedule.ColumnDefinitions.Add(scheduleTitleColumn); 

      ColumnDefinition viewBtnColumn = new ColumnDefinition(); 
      //gl2 to hold the view alarm button 
      GridLength viewBtnGrid = new GridLength(80); 
      viewBtnColumn.Width = titleGrid; 
      schedule.ColumnDefinitions.Add(viewBtnColumn); 
      //text block that show the label of the alarm 
      TextBlock titleTxtBlock = new TextBlock(); 
      titleTxtBlock.Text = time; 

      //Set the alarm label text block properties - margin, fontsize 
      titleTxtBlock.FontSize = 30; 
      titleTxtBlock.Margin = new Thickness(20, 20, 0, 0); 
      Grid.SetColumn(titleTxtBlock, 0); 
      //set the view alarm details button and its properties - margin, width, height, name, background, font size 
      HyperlinkButton viewButton = new HyperlinkButton(); 
      viewButton.Margin = new Thickness(-150, 20, 0, 0); 
      viewButton.Width = 100; 
      viewButton.Height = 50; 
      viewButton.Name = time; 
      viewButton.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("/AlarmClock;component/Images/page_preview.png", UriKind.Relative)) }; 
      viewButton.FontSize = 30; 
      //viewButton.NavigateUri = new Uri("/viewAlarmClock.xaml?label=" + timeList, UriKind.Relative); 
      Grid.SetColumn(viewButton, 1); 
      schedule.Children.Add(titleTxtBlock); 
      schedule.Children.Add(viewButton); 

      //Add the alarm details to alarmListBox 
      scheduleListBox.Items.Add(schedule); 
     } 
    } 
} 

但我上面的代碼給了我一個錯誤,指出異常是未處理:0x8000ffff

我該如何修改我的上述代碼?

+0

爲什麼不使用XAML和數據綁定? –

+1

,因爲我想嘗試這種方法。我在 –

+0

之前進行了數據綁定,因此將您的代碼逐行註釋到錯誤消失。然後你知道什麼是錯的。 –

回答

0

Grid創建代碼沒有任何問題。最有可能的例外是它的範圍之外。請確保:

  • 您的應用程序沒有調用功能沒有在應用 清單
  • 在獨立存儲存在並且可訪問的文件中聲明

是循環在你的情況達到了?