开发者

Getting value of TextBlock inside AutoCompleteBox DataTemplate

开发者 https://www.devze.com 2023-03-26 17:32 出处:网络
How do I get the value of a TextBlock inside an WPF AutoCompleteBox container within a DataTemplate? 开发者_开发知识库Below is my AutoCompleteBox XAML

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

精彩评论

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

关注公众号