1
현재 Azure 모바일 서비스 SQL 데이터베이스에 저장된 응용 프로그램 데이터가 있습니다. 데이터베이스에서 항목을 가져 와서 목록보기에 표시하고 있습니다. 사용자가 목록보기에서 항목을 클릭하면 데이터베이스의 특정 레코드에 대한 자세한 정보를 표시하는 새 페이지로 이동합니다.Azure에서 데이터를 가져 와서 MainPage 및 ItemPage에 표시
메인 페이지 코드 :
public class OSVersions
{
[JsonProperty(PropertyName = "id")]
public int id { get; set; }
[JsonProperty(PropertyName = "Version")]
public string Version { get; set; }
[JsonProperty(PropertyName = "Codename")]
public string Codename { get; set; }
[JsonProperty(PropertyName = "Publish")]
public bool Publish { get; set; }
[JsonProperty(PropertyName = "ReleaseDate")]
public DateTime ReleaseDate { get; set; }
[JsonProperty(PropertyName = "Changes")]
public string Changes { get; set; }
[JsonProperty(PropertyName = "Notes")]
public string Notes { get; set; }
}
public partial class OSMainVIew : PhoneApplicationPage
{
private MobileServiceCollection<OSVersions, OSVersions> items;
private IMobileServiceTable<OSVersions> osTable =
App.MobileService.GetTable<OSVersions>();
public OSMainVIew()
{
InitializeComponent();
}
private async void RefreshOSItems()
{
progressBar1.IsEnabled = true;
progressBar1.IsIndeterminate = true;
items = await osTable
.Where(OSItem => OSItem.Publish == true)
.ToCollectionAsync();
MainListBox.ItemsSource = items;
progressBar1.IsEnabled = false;
progressBar1.Visibility = System.Windows.Visibility.Collapsed;
progressBar1.IsIndeterminate = false;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
RefreshOSItems();
}
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainListBox.SelectedIndex == -1)
return;
NavigationService.Navigate(new Uri("/ViewModels/OS/OSItemView.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));
MainListBox.SelectedIndex = -1;
}
}
항목 페이지 코드 :
public partial class OSItemView : PhoneApplicationPage
{
private MobileServiceCollection<OSVersions, OSVersions> items;
private IMobileServiceTable<OSVersions> osTable =
App.MobileService.GetTable<OSVersions>();
public OSItemView()
{
InitializeComponent();
if ((Application.Current as App).IsTrial)
{
//textBlock1.Text = "Change Log available in full version only!";
//textBlock2.Visibility = System.Windows.Visibility.Collapsed;
}
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
string selectedIndex = "";
int buildID;
int idValue;
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
//Start progressBar
progressBar1.IsEnabled = true;
progressBar1.IsIndeterminate = true;
//Convert selectedIndex -> buildID
idValue = Convert.ToInt32(selectedIndex);
buildID = idValue + 1;
/* buildID = idValue + 1 becuase on OSMainView
* Items stored in the ListBox are each even an index number
* The first number is '0'
* This is a problem because the first IDNumber in the Database is '1'
* This isn't the best way to handle this, becuase even though the id field is an auto-increamental field,
* sometimes values are skipped and rows are deleted.
*/
//Query database
items = await osTable
.Where(OSItem => OSItem.id == buildID)
.ToCollectionAsync();
MainListBox.ItemsSource = items;
//End progressBar
progressBar1.IsEnabled = false;
progressBar1.Visibility = System.Windows.Visibility.Collapsed;
progressBar1.IsIndeterminate = false;
}
}
}
항목 페이지 XAML 코드 :
<Grid x:Name="ContentPanel" Margin="10,97,12,0" Grid.RowSpan="2">
<ListBox x:Name="MainListBox" Margin="10,-35,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,0" Width="432" Height="*">
<TextBlock TextWrapping="Wrap" Text="{Binding Version}" Style=" {StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="Notes" FontFamily="Segoe WP Bold" Foreground="{StaticResource PhoneAccentBrush}" Height="30" HorizontalAlignment="Left" Margin="0,1,0,0" Name="textBlock3" Padding="0" VerticalAlignment="Top" Width="444" />
<TextBlock x:Name="notesText" Text="{Binding Notes}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Height="180" VerticalAlignment="Top" HorizontalAlignment="Stretch" FontFamily="Segoe WP SemiLight" Margin="0" Width="455"/>
<TextBlock Text="Change Log" Height="30" HorizontalAlignment="Left" Margin="0,222,0,0" Name="textBlock1" VerticalAlignment="Top" FontFamily="Segoe WP Bold" Foreground="{StaticResource PhoneAccentBrush}" Width="444" Padding="0" />
<TextBlock Name="textBlock2" Text="{Binding Changes}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontFamily="Segoe WP SemiLight" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
MainListBox.ItemsSource = items;
이 실행되면 내 문제가 발생합니다. 응용 프로그램이 오류 코드없이 종료됩니다.
아이디어가 있으십니까?
해당 항목에 디버그 중단 점을 넣으십시오. ** 항목 **에 무엇이 있습니까? MainListBox 템플릿에 대한 데이터 바인딩에서 질식하는 뭔가가 출력 창에 표시됩니다. –
@ JimO'Neil 'Items'는 기술적으로 단 한 행이어야합니다. 그러나 나는 어떤 오류도 내지 않고있다. 항목 페이지에 대한 XAML 코드로 게시물을 업데이트했습니다. –
항목을 채우고 바로 그 행의 각 필드에 대해 디버거에서 무엇을 볼 수 있습니까? 나도 여기 보이는 것처럼 보이지 않는 것을 발견하지 못한다. 당신이 게시 할 수있는 작은 실행 VS 예제가 있습니까? –