获取所选列表项的对象属性 [英] Get Object properties of selected list item

查看:38
本文介绍了获取所选列表项的对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框,它有一个列表源,它是一个结果"对象列表.结果类如下所示:

I have a listbox that has a listsource that is a list of 'results' objects. The results class looks like this:

public class Result
{
    public string GUID { get; set; }
    public string __invalid_name__I { get; set; }
    public string FN { get; set; }
    public string DOB { get; set; }
    public string SEX { get; set; }
    public string SN { get; set; }
    public string __invalid_name__U { get; set; }
    public string TYPE { get; set; }        

    //Gender icon path associated with result
    public string SexIcon { get; set; }
}

这是我的列表框在 xaml 代码中的样子:

And this is what my listbox looks like in the xaml code:

<ListBox 
            Height="517" 
            HorizontalAlignment="Left" 
            Margin="12,84,0,0" 
            Name="searchList" 
            VerticalAlignment="Top" 
            Width="438" 
            SelectionChanged="SearchList_SelectedEvent">

            <!-- What each listbox item will look like -->
            <ListBox.ItemTemplate>
                <DataTemplate>                        
                    <StackPanel Orientation="Horizontal">

                        <Image Source="{Binding Path=Sex, Converter={StaticResource SexToSourceConverter}}" Visibility="Visible" />                            
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Name="FirstName" Text="{Binding FN}" FontSize="28" Margin="0,0,10,0"/>
                                <TextBlock Name="LastName" Text="{Binding SN}" FontSize="28" />
                            </StackPanel>
                            <TextBlock Text="{Binding DOB}" FontSize="24" />
                            <!-- Line Stroke="#FF04863C" StrokeThickness="3" X1="100" Y1="100" X2="300" Y2="100" / -->
                        </StackPanel>
                    </StackPanel>                            
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>

所以我的问题是,(以及我真正在努力解决的问题)例如,如何获取所选项目(基本上是一个结果对象)的 GUID 属性的值?

So my question is, (and what I'm really struggling with) is how does one for instance get the value of the GUID property of the selected Item (which is basically a results object)?

推荐答案

(searchList.SelectedItem as Result).GUID

(searchList.SelectedItem as Result).GUID

这篇关于获取所选列表项的对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆