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

  • Home
  • SEARCH
  • 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 117163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:17:34+00:00 2026-05-11T03:17:34+00:00

I have a ComboBox in WPF which is databound, and has data template which

  • 0

I have a ComboBox in WPF which is databound, and has data template which controls how each of the items is displayed. I have made it so that each item is displayed with two bits of text (for the Name and Path properties) and one image (for the Icon property).

At the moment when I select an item from the ComboBox the textbox bit of the ComboBox just changes to say ‘TestWPF.Result’ which is the name of the class which I have populated the ComboBox with.

I’m interested in one (or both) of two things:

  1. How do I change it so that it displays the value of one of the fields there (eg. so it shows the value of the Name field rather than the name of the class)?

  2. Is it possible get it to use the same DataTemplate there as in the list of items, so that once I have selected an item it displays in the closed ComboBox the same way as it looks in the list of items. Basically I’ve got a DataTemplate called ShowResults and a ComboBox which uses that template. I’ve also added in a separate ContentControl which I’ve got to show the details of the selected item in the ComboBox, but I want to get that to replace the textbox in the ComboBox.

Update:

Thanks for the first answer. I’ve tried using a separate ContentControl, as you’ve described, and it works fine. The question now is how to replace the textbox part of the ComboBox with this ContentControl. Any hints on that would be most welcome.

Also, is it possible to replace the textbox bit of the ComboBox control with a mixture of the ContentControl and a textbox, so that I can still type in the textbox to help select items from the ComboBox, but then when I close the dropdown the rest ContentControl bit will be populated with the rest of the text and the icon. Hope that makes sense – ask questions if it doesn’t!

Code:

I’ve been asked to post my code – so here it is. I’ve tried to remove things that I know are definitely not relevant, but I’m not sure exactly what is relevant so when in doubt I’ve left things in.

<Window x:Class='TestWPF.Window1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:custom='clr-namespace:TestWPF' Title='Window1' Height='300' Width='843' Loaded='Window_Loaded'> <Window.Resources>     <DataTemplate x:Key='ShowResult' DataType='TestWPF.Result'>         <StackPanel Margin='5' Orientation='Horizontal'>             <Image Width='32' Height='32'  Source='{Binding Path=Image}'/>             <StackPanel Margin='5'>                 <TextBlock FontWeight='Bold' Text='{Binding Path=Name}'/>                                     <TextBlock Text='{Binding Path=Path}'/>             </StackPanel>         </StackPanel>     </DataTemplate> </Window.Resources>  <Grid Width='786'>     <Button Height='23' HorizontalAlignment='Right' Margin='0,24,166,0' Name='btnTest' VerticalAlignment='Top' Width='75' Click='btnTest_Click'>Add</Button>     <ComboBox StaysOpenOnEdit='True'  DropDownClosed='comboBox1_DropDownClosed' PreviewTextInput='comboBox1_PreviewTextInput' SelectionChanged='comboBox1_SelectionChanged' ItemTemplate='{StaticResource ShowResult}'  Margin='259,109,22,89' Name='comboBox1' IsEditable='True' />     <ContentControl Height='50' Margin='268,0,22,21' Name='contentControl1' VerticalAlignment='Bottom' Content='{Binding ElementName=comboBox1,Path=SelectedValue}' ContentTemplate='{StaticResource ShowResult}'/> </Grid> 

  • 1 1 Answer
  • 4 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. 2026-05-11T03:17:34+00:00Added an answer on May 11, 2026 at 3:17 am

    Just place the Property Binding expression to the textBox,You dont need to apply template.

    Another way to get exact Data template, Place a ContentControl in the place of textBox and assign the same DataTemplate (say x:Name=’robinTemplate’)

    <ContentControl Content='{Binding ElementName=cmbBox,Path=SelectedValue}' ContentTemplate='{StaticResource robinTemplate}'/> 

    For making the Selected content display in the same way : Create a copy of the combobox control template and you will find a ContentPresenter there. Replace that with the ContentControl.. This is not the right solution though.

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

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer alt text http://dl.getdropbox.com/u/317805/path2.jpg The graph above is transformed to below… May 11, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer Ways I know about are: a) Put the other assemblies… May 11, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer Turns out that this was because the window that the… May 11, 2026 at 6:12 pm

Related Questions

Update After a bit of investigating. What seems to be the issue is that
I have a ComboBox in WPF whose ItemsSource is set to a list programmatically.
I have an object of Type MyTypeOneViewModel that is displayed in the first column
I know in ASP.NET I can get an item from a DropDownList by using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.