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 3616652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:31:31+00:00 2026-05-18T22:31:31+00:00

I am very new to WPF and testing some things that I would like

  • 0

I am very new to WPF and testing some things that I would like to include in an application that I will be working on. I have a 2 row ListView (bound to a textbox) with the names Scott Guthrie and Jon Skeet in it. I am trying to select “Scott Guthrie” in the ListView and have it populate the TextBox. I want to be able to edit the text and tab off and have the ListView updated.

Edit:I removed the code since that really didn’t add anything to the question.

  • 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-18T22:31:31+00:00Added an answer on May 18, 2026 at 10:31 pm

    Wow, that’s really complicated what you’ve got there.

    This can be accomplished in a very simple way. You need a model to represent the programmer, a view model to hold a list of programmers, and simple binding to take care of the rest.

    The model:

    public sealed class Programmer
    {
        public string Name { get; set; }
    }
    

    Its very simple. An object representing a programmer with a name. We must encapsulate the name within an object because strings are immutable in .NET. If you tried binding against a single string in a list of strings, changes wouldn’t propagate.

    The collection of programmers is kept in a ViewModel. In this case, I call it ViewModel, because I have no imagination. This view model contains everything that the view binds against. In this case, its the list of programmers.

    public sealed class ViewModel
    {
        public ObservableCollection<Programmer> Programmers { get; private set; }
    
        public ViewModel()
        {
            Programmers = new ObservableCollection<Programmer>();
        }
    }
    

    The ViewModel is set as the DataContext of our view. The DataContext flows down the visual tree, and we can bind against it at any point.

    public MainWindow()
    {
        var vm = new ViewModel();
        vm.Programmers.Add(new Programmer { Name = "Jon Skeet" });
        vm.Programmers.Add(new Programmer { Name = "Scott Guthrie" });
        DataContext = vm;
        InitializeComponent();
    }
    

    You can set the DataContext in any way you want; I’m doing it here for simplicity’s sake.

    In the UI, I simply bind the ListView against the list of Programmers in the ViewModel (the DataContext, unless otherwise stated, is the root of the binding path). I then bind the TextBox against the SelectedItem of the ListBox. You select a Programmer from the list, which then becomes the SelectedItem, which I can then change the Name of.

    <Window
        x:Class="Programmers.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:t="clr-namespace:Programmers"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ListBox
                x:Name="list"
                ItemsSource="{Binding Programmers}"
                DisplayMemberPath="Name" />
            <TextBox
                Grid.Column="1"
                VerticalAlignment="Top"
                Text="{Binding SelectedItem.Name, ElementName=list}" />
        </Grid>
    </Window>
    

    Simple, once you get the hang of it.

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

Sidebar

Related Questions

I still very new using Subversion. Is it possible to have a working copy
I'm very new to WPF, so please bear with me. Basically I have defined
I'm very new to WPF: I need to have buttons on a grid resize
I am very new to WPF and am trying to set up an application
I have a main wpf form that opens a new form. However when that
I have encountered something very strange, simple WPF application <Window x:Class=ListBoxSelection.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow
I'm VERY new to WPF, and still trying to wrap my head around binding
I am very new to creating webservers - and I have had several goes
Hi I'm very new to sql but have been passed a job in which
I'm very new to WPF, so I've just started making a very simple Memory

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.