私がやろうとしているのは、リスト ボックスで選択した項目のプロパティ値を取得することです。
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
//listBox1.Items.Clear();
IList<FoodViewModel> food = this.Getfoodlist();
List<Foodlist> foodItems = new List<Foodlist>();
foreach (FoodViewModel foodlist in food)
{
int foodID = foodlist.C_ID;
string foodDetail = foodlist.FoodDetail;
string foodTime = foodlist.FoodTime;
string foodDate = foodlist.DateofFood;
foodItems.Add(new Foodlist() { C_ID = foodID, FoodTime = foodTime, DateofFood = foodDate, FoodDetail = foodDetail});
}
listBox1.ItemsSource = foodItems;
}
public class Foodlist
{
public int C_ID { get; set; }
public string DateofFood{ get; set;}
public string FoodTime{ get; set;}
public string FoodDetail{ get; set;}
}
XAML コード -
<ListBox Height="528" HorizontalAlignment="Left" Margin="1,4,0,0" Name="listBox1" VerticalAlignment="Top" Width="453">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Name="foodDetail"
Text="{Binding FoodDetail}" />
<TextBlock Name="date"
Text="{Binding DateofFood}" />
<TextBlock Name="time"
Text="{Binding FoodTime}" />
<TextBlock Name="ID"
Text="{Binding C_ID}" Visibility="Collapsed" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
今、取得したいのは、選択したリストボックス項目の C_ID(値) です。助言がありますか?