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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:58:19+00:00 2026-05-25T14:58:19+00:00

This should be really easy, I just want to update the listview when the

  • 0

This should be really easy, I just want to update the listview when the user adds something in the textbox to my observable collection.

I don’t understand why I can’t get this working:

XAML

<Window x:Class="MyStuff.WPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="486" Width="540" WindowStyle="SingleBorderWindow" ResizeMode="NoResize" >
    <Grid>
        <Menu IsMainMenu="True" VerticalAlignment="Top" HorizontalAlignment="Stretch" FlowDirection="LeftToRight">
            <MenuItem Header="File" >
                <MenuItem Header="Open File..">
                </MenuItem>
                <MenuItem Header="Exit">
                </MenuItem>
            </MenuItem>               
        </Menu>
        <TextBox Height="36" HorizontalAlignment="Left" Margin="12,27,0,0" Name="textBoxSearchTerm" VerticalAlignment="Top" Width="414" FontSize="24" MaxLength="80" AcceptsReturn="False" Background="#FFFFFFE8" Text="asdfasdf" FontWeight="Bold" FontFamily="Calibri" FontStretch="Normal" />
        <Button Content="Add" Height="36" HorizontalAlignment="Left" Margin="435,27,0,0" VerticalAlignment="Top" Width="68" FontSize="20" FontWeight="Normal" FontFamily="Calibri" Click="AddSearchTerm_Click" />

        <ListView Height="338" HorizontalAlignment="Left" Margin="12,97,0,0" Name="listView1" VerticalAlignment="Top" Width="261" ItemsSource="{Binding SearchTerms}">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="120" Header="Search Term" DisplayMemberBinding="{Binding}" />
            </GridView>
        </ListView.View>
    </ListView>

    </Grid>
</Window>

Code Behind

public partial class MainWindow : Window
{
    public ObservableCollection<string> searchItems = new ObservableCollection<string>();

    public MainWindow()
    {
        InitializeComponent();
    }

    // DEFINE A PROPERTY..
    public ObservableCollection<string> SearchItems
    {
        get { return searchItems; }
    }

    private void AddSearchTerm_Click(object sender, RoutedEventArgs e)
    {
        searchItems.Add(textBoxSearchTerm.Text);
    }
}
  • 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-25T14:58:19+00:00Added an answer on May 25, 2026 at 2:58 pm

    Tigrans answer is correct with regards to setting the datacontext. This is required to do databinding. There are a number of ways this can be accomplished but the easiest way would be to set the datacontext to your viewmodel (SearchItems).

    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = SearchItems;
    }
    

    Then your binding would look like <ListView ... ItemSource={Binding}>
    Also you have {Binding SearchTerm} a couple times but i do not see a property that it would be binding to (maybe a typo).

    Another option for binding the DataContext is to set it to the control itself:

    this.DataContext = this;
    

    This will change your binding expressions to {Binding Path=SearchItems} as this will tell the binding engine to look for the SearchItems property on the current datacontext.

    Hope this helps.

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

Sidebar

Related Questions

This really should be easy, but I just can't work it out myself, the
This feels like it should be really easy, but I just can't get it
This should be straight forward for a guru. I don't have any code really
This might be something very straight forward and I really think it should work
Seems like this should be easy or at least documented somewhere, I just cant
this should be an easy one and I really thought that what I was
This should really be allowed - I do not understand why it is not.
This should be really simple, but I have tried many solutions posted on the
This should be a really really simple thing, but for some reason it is
Overview I am using CompositeWPF to create an app using C#. This really should

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.