<i id='tNULU'><tr id='tNULU'><dt id='tNULU'><q id='tNULU'><span id='tNULU'><b id='tNULU'><form id='tNULU'><ins id='tNULU'></ins><ul id='tNULU'></ul><sub id='tNULU'></sub></form><legend id='tNULU'></legend><bdo id='tNULU'><pre id='tNULU'><center id='tNULU'></center></pre></bdo></b><th id='tNULU'></th></span></q></dt></tr></i><div id='tNULU'><tfoot id='tNULU'></tfoot><dl id='tNULU'><fieldset id='tNULU'></fieldset></dl></div>

      1. <tfoot id='tNULU'></tfoot>

        <small id='tNULU'></small><noframes id='tNULU'>

        <legend id='tNULU'><style id='tNULU'><dir id='tNULU'><q id='tNULU'></q></dir></style></legend>

        • <bdo id='tNULU'></bdo><ul id='tNULU'></ul>

        从 ListBox 中单击的项目中获取数据

        时间:2023-10-07
      2. <small id='X7gqo'></small><noframes id='X7gqo'>

        <tfoot id='X7gqo'></tfoot>
        <legend id='X7gqo'><style id='X7gqo'><dir id='X7gqo'><q id='X7gqo'></q></dir></style></legend>
          <tbody id='X7gqo'></tbody>

          • <bdo id='X7gqo'></bdo><ul id='X7gqo'></ul>
                • <i id='X7gqo'><tr id='X7gqo'><dt id='X7gqo'><q id='X7gqo'><span id='X7gqo'><b id='X7gqo'><form id='X7gqo'><ins id='X7gqo'></ins><ul id='X7gqo'></ul><sub id='X7gqo'></sub></form><legend id='X7gqo'></legend><bdo id='X7gqo'><pre id='X7gqo'><center id='X7gqo'></center></pre></bdo></b><th id='X7gqo'></th></span></q></dt></tr></i><div id='X7gqo'><tfoot id='X7gqo'></tfoot><dl id='X7gqo'><fieldset id='X7gqo'></fieldset></dl></div>
                  本文介绍了从 ListBox 中单击的项目中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Windows Phone 新手,

                  I am new to Windows Phone,

                  我有一个包含文本块的列表框,我想从列表框中的选定项目中获取所有数据.

                  I have one listbox with textblocks in it, I want to fetch all data from selected item in listbox.

                  这是我的代码片段:

                  .xaml 文件

                   <ListBox HorizontalAlignment="Left" Name="listbox1" ItemsSource="{Binding}" Margin="9,10,0,0" SelectionChanged="listBox1_SelectionChanged">
                                <ListBox.ItemTemplate>
                                      <DataTemplate>
                                              <StackPanel Margin="0,0,0,5">
                                                   <Image HorizontalAlignment="Left" Height="100" Margin="0,15,0,0" VerticalAlignment="Top""/>
                                                   <TextBlock Text="{Binding AttractionName}" Foreground="Yellow" Margin="120,-110,0,0""/>
                                                   <TextBlock Text="Price:" Foreground="White" TextWrapping="Wrap" FontSize="30""/>
                                                   <TextBlock Text="" Foreground="Green" TextWrapping="Wrap" FontSize="40" Margin="200,-50,12,0""/>
                                                   <TextBlock Text="{Binding price}" Foreground="Green" FontSize="40""/>
                                                   <Line X1="0" X2="420" Y1="10" Y2="10" Stroke="White" VerticalAlignment="Bottom"/>
                                          </StackPanel>
                                      </DataTemplate>
                                </ListBox.ItemTemplate>
                  </ListBox>
                  

                  .cs 文件

                      void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs args)
                      {
                          Debug.WriteLine(" You selected " +listbox1.SelectedItem.ToString());
                      }
                  

                  我的控制台以这种方式显示输出:You selected Appname.Pagename.methodname

                  My console shows output this way: You selected Appname.Pagename.methodname

                  与 ListBox 绑定的类

                  Class which is bound to ListBox

                      public class Attractions { 
                  [JsonProperty("AttractionName")]
                   public string AttractionName { get; set; }
                  [JsonProperty("IphoneImage")] 
                  public string IphoneImage { get; set; } 
                  [JsonProperty("price")] public string price { get; set; } 
                  }
                  

                  推荐答案

                  有几种方法可以做到:

                  private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs args)
                  {
                      if (listBox1.SelectedIndex == -1) return;
                  
                      Attractions first = listbox1.SelectedItem as Attractions ;
                      Attractions second = (Attractions)listBox1.Items[listBox1.SelectedIndex];
                      Attractions third = (sender as ListBox).SelectedItem as Attractions;
                      Attractions fourth = args.AddedItems[0] as Attractions;
                  
                      Debug.WriteLine(" You selected " + first.AttractionName);
                  }
                  

                  使用 SelectedItem (Index),您将获得一个属于您的 ItemsSource 集合的类型的项目.获得物品后,您可以随心所欲地使用它.

                  With SelectedItem (Index) you get an item that is Type of your ItemsSource Collection. Once you get the item you can do what you want with it.

                  这篇关于从 ListBox 中单击的项目中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 ListBox 中将第一项加粗? 下一篇:如何更改列表框中单词的颜色

                  相关文章

                      <i id='PBVAf'><tr id='PBVAf'><dt id='PBVAf'><q id='PBVAf'><span id='PBVAf'><b id='PBVAf'><form id='PBVAf'><ins id='PBVAf'></ins><ul id='PBVAf'></ul><sub id='PBVAf'></sub></form><legend id='PBVAf'></legend><bdo id='PBVAf'><pre id='PBVAf'><center id='PBVAf'></center></pre></bdo></b><th id='PBVAf'></th></span></q></dt></tr></i><div id='PBVAf'><tfoot id='PBVAf'></tfoot><dl id='PBVAf'><fieldset id='PBVAf'></fieldset></dl></div>

                      <tfoot id='PBVAf'></tfoot>
                        <bdo id='PBVAf'></bdo><ul id='PBVAf'></ul>
                    1. <small id='PBVAf'></small><noframes id='PBVAf'>

                    2. <legend id='PBVAf'><style id='PBVAf'><dir id='PBVAf'><q id='PBVAf'></q></dir></style></legend>