Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 200831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:08:45+00:00 2026-05-11T17:08:45+00:00

Im trying to get my head wrapped around the WPF model. I have a

  • 0

I”m trying to get my head wrapped around the WPF model.

I have a list box of items. Inside the list box items are string identifiers. This works fine. What I want is to have it so that the identifier from the currently selected item is accessible in my code-behind for the enclosing control.

I have this:

<ListBox.ItemTemplate>
 <DataTemplate>
   <StackPanel Width="320">
    <Label Content="{Binding Path=ShortName}" Style="{StaticResource ListHeader}"/>
      <TextBlock TextWrapping="Wrap" Text="{Binding Path=Description}" Style="{StaticResource ListText}" />
   </StackPanel>
 </DataTemplate>
 </ListBox.ItemTemplate>

And I think I should add something like:

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
    <Setter Property="" TargetName="">
     <Setter.Value>

     </Setter.Value>
   </Setter>
 </DataTrigger>

But I’m lost as to how to set-up the setter to set a property that’s part of the enclosing control (ie, the outside world). I think I have this backwards somehow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:08:45+00:00Added an answer on May 11, 2026 at 5:08 pm

    If you are trying to access a property on a selected list box item from outside of the listbox then you can do the following in your code behind:

    CustomItem item = (CustomItem)listBox1.SelectedItem;
    MessageBox.Show(item.ShortName);
    

    And your xaml is as follows:

    <ListBox Height="100" Name="listBox1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Name="stackPanel1">
                        <Label Content="{Binding Path=Shortname}"/>
                        <TextBlock Text="{Binding Path=Description}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    

    You just cast the selecteditem from the listbox to your object type, then access the property on the object.

    Hope this is what you were after.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to get my head around Generics by reading this enlightening article by
I'm trying to get my head around why the following doesn't work. I have
I am desperately trying to get my head wrapped around how to implement home
I'm trying to use OAuth with Twitter, and I have my head wrapped around
just exploring c# 4. Trying to get my head around all this dynamic stuff.
I'm trying to get my head wrapped around tangent space and I'm starting to
Just trying to get my head round WPF. I have a usercontrol which I'm
I was trying to get my head around jQuery's Ajax. I have a page
I was trying to get my head around XAML and thought that I would
I'm trying to get my head around the Error Handling in MVC. What I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.