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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:53:39+00:00 2026-05-14T19:53:39+00:00

i started a WPF application (with vs 2008 sp1) which connects to a web

  • 0

i started a WPF application (with vs 2008 sp1) which connects to a web service to get Collection of objects.
I can be contactInfo[] or groupInfo[].
here is my main.xaml.cs

 public main()
    {
        InitializeComponent();
        //service.addContactCompleted +=new addContactCompletedEventHandler(addContactCompleted);
        service.getContactsCompleted += new getContactsCompletedEventHandler(getContactsCompleted);
        fillContents();
    }

private void getContactsCompleted(object sender, getContactsCompletedEventArgs e)
    {
        try
        {
            //e.Result return contactInfo[]
            contactListBox.ItemsSource = e.Result;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }


    public void fillContents()
    {
        service.getContactsAsync(session.key, null);


    }

and this is my main.xaml

 <Window.Resources>
    <ObjectDataProvider x:Key="contactInfo" ObjectType="{x:Type serviceAdmin:contactInfo}" />
</Window.Resources>
<Grid>
                <ListBox Margin="-146,-124,-143,-118.808" Name="contactListBox" ItemsSource="{Binding Source={StaticResource contactInfo}}" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Label Content="{Binding fullName}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <!--<toolkit:DataGrid Margin="-146,-124,-150,-118.808" Name="contactGrid"  ItemsSource="{Binding}"/>-->
</Grid>

this partially works but just that it returns repeated values. it just repeats which ever comes first.I’ll like to know what i’m doing wrong here.Can anyone shed some light?? thanks for reading 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-14T19:53:40+00:00Added an answer on May 14, 2026 at 7:53 pm

    Looks like you are binding your ListBox to the wrong source. First of all, I don’t really see why you need to have to ObjectDataSource at all. You can just bind the ItemsSource of the ListBox to your collection, like you did. But also (as a commenter pointed out), keep in mind that you are accessing the UI on a different thread, so you should use calls to Dispatcher to fill up your listbox.
    Maybe something like this:

     public main()
    {
        InitializeComponent();
        service.getContactsCompleted += new getContactsCompletedEventHandler(getContactsCompleted);
        fillContents();
    }
    
    private void getContactsCompleted(object sender, getContactsCompletedEventArgs e)
    {
        try
        {
            //e.Result return contactInfo[]
            Dispatcher.Invoke(new Action<List<contactInfo>>(list => contactListBox.ItemsSource = list), e.Result);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    
    public void fillContents()
    {
        service.getContactsAsync(session.key, null);
    }
    

    your xaml can be greatly simplified to this:

    <Grid>
       <ListBox Margin="-146,-124,-143,-118.808" Name="contactListBox" DisplayMember="fullName" />
    </Grid>
    

    HTH,
    Roel

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

Sidebar

Related Questions

I created a wpf application which have a single window which is getting started
I've started a WPF (web-based) application and it has multiple pages. I want to
I have a wpf C# application that calls a web service AddressValidationService. I know
I've recently started creating a WPF application, and am just hoping that someone can
I have a working database application using WPF and SQL Server 2008 R2, which
We are using the prism and WPF to build application. Recently we started using
Working on a WPF application, I started working on a custom ControlTemplate . I
I need to know if my wpf application is started from startup folder or
I have a WPF application in which I'm moving data around on a Canvas.
I've started the development of a windows application, which target windows 7 and vista

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.