【问题标题】:How can select a item from listbox binding Windows Phone 7如何从列表框绑定 Windows Phone 7 中选择一个项目
【发布时间】:2014-08-30 18:22:21
【问题描述】:

我无法使用 SELECTEDITEM 事件从列表框中获取文本,但它不会并且仅返回像“Li.Medicamento”这样的字符串。

我的代码 xaml:

<ListBox x:Name="list_enfer" Margin="38,210,40,65" Visibility="Collapsed"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding enfermedadasoc}"></TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

我的 C# 代码如下:

private void visualizar_est_Click(object sender, System.EventArgs e) { MessageBox.Show(list_enfer.SelectedItem.ToString()); }

【问题讨论】:

    标签: c# xaml windows-phone-7 listbox


    【解决方案1】:
    private void visualizar_est_Click(object sender, System.EventArgs e)
            {
                 var mySelectedItem = list_enfer.SelectedItem as yourObject;
                 //Then you can access the property inside yourObject
                 MessageBox.Show(yourObject.enfermedadasoc.ToString()); 
            }
    

    【讨论】:

    • 你提到你的对象是什么意思?
    • @user3621634 您在代码中绑定到列表框的类名。发布您设置 ItemsSource 的部分
    猜你喜欢
    • 2012-05-30
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 2011-03-29
    相关资源
    最近更新 更多