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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:43:28+00:00 2026-05-16T04:43:28+00:00

Hai am using wpf list box, i cannot able to clear the list when

  • 0

Hai am using wpf list box, i cannot able to clear the list when am calling the reload data function, i just want to reload new data at runtime,while page loading it loads the data correctly, when i refresh the new data is fetched in itemsource i can see that in debug mode, but no new data in listbox, old data remains in the list, i cant even clear, when i call list.items.clear(), it throws exception and app crashes, i tried lot ways, is ther any problem in my XAML binding, the following is my code.

<DataTemplate x:Key="listBoxTemplate">
                <StackPanel Margin="3">
                    <DockPanel >
                        <TextBlock FontWeight="Bold" Text="{Binding Name}" DockPanel.Dock="Left" Margin="5,0,10,0"/>
                        <TextBlock Text="  " />
                         <TextBlock Text="{Binding Percnt}" Foreground="Green" FontWeight="Bold" />
                   </DockPanel>                       
                </StackPanel>
            </DataTemplate>

My listbox

 <ListBox Height="898" Name="lstEntity" Width="291" ItemTemplate="{StaticResource listBoxTemplate}" SelectionChanged="lstEntity_SelectionChanged"/>

Binding code

   lstEntity.ItemsSource = sei.getNames();

getNames() function just returns the data as list,nothing special code in that, How to resolve this.

  • 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-16T04:43:28+00:00Added an answer on May 16, 2026 at 4:43 am

    The best way to get this type of behavior is to use a DependencyProperty and bindings.

    In your class file create the DP like so:

        #region MyList dependency property
        public static readonly DependencyProperty MyListProperty = DependencyProperty.Register("MyList", typeof(ObservableCollection<String>), typeof(Window1));
    
        public ObservableCollection<String> MyList
        {
            get { return (ObservableCollection<String>) GetValue(MyListProperty); }
            set { SetValue(MyListProperty, value); }
        }
        #endregion
    

    Then in you XAML bind to that DP like so:

    <ListBox ItemSource={Binding Path=MyList, ElementName=MyWindow} Height="898" Name="lstEntity" Width="291" ItemTemplate="{StaticResource listBoxTemplate}" SelectionChanged="lstEntity_SelectionChanged"/>
    

    Where “MyWindow” is the x:Name of the root window in you XAML file (you could of course use datacontext like the MVVM pattern as well 🙂

    Then if you want to add/remove items from your code you just access the list directly:

    MyList.Clear();
    MyList.Add("My New String");
    

    You will, of course, also need to change the Generic type of the collection to be your own class…

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

Sidebar

Related Questions

Hai, Am using DevExpress LookupEdit in C#.NET application.I want to clear all items in
Hai am using telerik wpf grid in grid selection change event am getting the
Hai I am using codeigniter...I my function phpcalview() ... This is my function function
Hai tried to get the latitude and longtitude value using service class.my service function
hai.all..can you tell me how to make table in jquery? i want using this
Hai guys, As i want to develop an application using asp.net MVC, i dont
Hai am Calling the webservice in my android application am using android version(r-18).but i
Hai! I am new to android. I want to store the images into the
hai friends In my application i want to send sms using nokia 3310c mobile
hai.. just i wrote application for show preview to user and capture image.am using

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.