2011-08-09 65 views
0

如何獲取DataTemplate中WPF AutoCompleteBox容器內的TextBlock的值?在AutoCompleteBox DataTemplate中獲取TextBlock的值

下面是我AutoCompleteBox XAML

<my:AutoCompleteBox Name="acLastName" 
    FilterMode="StartsWith" 
    SelectedItem="{Binding SelectedItem, Mode=TwoWay}" 
    SelectionChanged='acLastName_SelectionChanged' 
    ValueMemberPath="LastName"> 
     <my:AutoCompleteBox.ItemTemplate> 
      <DataTemplate x:Name='UserDetails'> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock x:Name='UserId' Text="{Binding UserDetailsId}"/> 
        <TextBlock Text="{Binding LastName}" /> 
        <TextBlock Text="{Binding FirstName}" /> 
        <TextBlock Text="{Binding UserId}" /> 
        <TextBlock Text="{Binding Comapany}" /> 
       </StackPanel> 
      </DataTemplate> 
     </my:AutoCompleteBox.ItemTemplate> 
</my:AutoCompleteBox> 

回答

0

acLastName.SelectedItem將是你的UserDetails對象。

投下那隻小狗和獲取UserDetailsId通過:

((UserDetails)acLastName.SelectedItem).UserDetailsId 
相關問題