【问题标题】:Get Object properties of selected list item获取选定列表项的对象属性
【发布时间】:2012-07-10 20:35:59
【问题描述】:

我有一个列表框,它的列表源是“结果”对象的列表。结果类如下所示:

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 代码中的样子:

<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 属性的值?

【问题讨论】:

标签: c# windows-phone-7 xaml


【解决方案1】:

(searchList.SelectedItem as Result).GUID

【讨论】:

  • 谢谢!但只是为了澄清,我是否在我的 listBox SelectionChanged="SearchList_SelectedEvent" 中使用它??
  • 我刚刚回答了我自己的问题...是的,我在我的 listBoxs 的 SelectinoChange 事件中使用它。
猜你喜欢
  • 2011-04-28
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 2014-02-04
  • 2017-06-29
  • 1970-01-01
  • 2011-08-31
  • 2013-01-28
相关资源
最近更新 更多