开发者

Getting value of TextBlock inside AutoCompleteBox DataTemplate

How do I get the value of a TextBlock inside an WPF AutoCompleteBox container within a DataTemplate?

开发者_开发知识库Below is my 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>


acLastName.SelectedItem will be your UserDetails object.

So cast that puppy up and access UserDetailsId through that:

((UserDetails)acLastName.SelectedItem).UserDetailsId
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜