問題
から選択した特定のアイテムに関する情報を表示しようとしていますListBox
。項目は、Azure Mobile Services SQL データベースからのものです。をキャプチャしてから、 が に等しいSelectedIndex
データベースにクエリを実行しようとしました。残念ながら、ユーザーにはデータを並べ替えるオプションが与えられているため、アイテムの ID をデータベースからのアイテムと一致しなくなった場所に変更します。RowID
SelectedIndex
RowID
Main.xaml からのコード
<Grid x:Name="ContentPanel" Margin="10,97,12,0" Grid.RowSpan="2">
<ListBox x:Name="MainListBox" Margin="10,10,-12,0" SelectionChanged="MainListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding FirstName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LastName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
どうにかして の値を取得し、それらの値に基づいてデータベースにクエリを実行することは可能でしょうFirstName
かLastName
?
更新 - Item.xaml からのコード
private MobileServiceCollection<Phones, Phones> items;
private IMobileServiceTable<Phones> phoneTable =
App.MobileService.GetTable<Phones>();
public PhoneItemView()
{
InitializeComponent();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var listItem = MainListBox.SelectedItem as Phones;
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
//Start progressBar
progressBar1.IsEnabled = true;
progressBar1.IsIndeterminate = true;
//Query database
try
{
items = await phoneTable
.Where(phone => phone.Model == listItem.Model)
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException)
{
MessageBox.Show("Error", "Error", MessageBoxButton.OK);
}
MainListBox.ItemsSource = items;
//End progressBar
progressBar1.IsEnabled = false;
progressBar1.Visibility = System.Windows.Visibility.Collapsed;
progressBar1.IsIndeterminate = false;
}
}
Main.xaml
プロパティから項目が選択されたページではMainListBox
、SelectedItem
上記のように Item.xaml ページに渡されます。これは、データベースのクエリに使用されます。これは正しいです?
編集 2
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/ViewModels/Phones/PhoneItemView.xaml?selectedItem=" + MainListBox.SelectedItem, UriKind.Relative));
}