WPF List<Contact>

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I am writing a WPF application, this is a Contact Manager App for practice..this is my first WPF project....

I have designed the UI in Photoshop and implimented it in WPC C# VS 2012. I have a listbox on the Main window...this is supposed to hold the Contact Info....I am having some trouble adding the info....I have created a Contact class and have public properties for the info I want to add to the listbox....then in the form load event I add each Contact to A List<Contact>..this is where I am having trouble...when I add the info...it doesnt show in the listbox corectly...all it adds is "MyBlackBook.Contact" for each contact added to the list..... code is below

  private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            contactList.Add(new Contact()
            {
                ID = "1",
                ContactName = "Gene | ",
                Address = "1234 right st | ",
                City = "AnyWhere | ",
                State = "State | ",
                Zip = "34221 | ",
                Birthday = "01/29/1970 | ",
                ImageSource = "#####"
            });


            contactList.Add(new Contact()
            {
                ID = "2",
                ContactName = "Gene | ",
                Address = "1234 right st | ",
                City = "AnyWhere | ",
                State = "State | ",
                Zip = "34221 | ",
                Birthday = "01/29/1970 | ",
                ImageSource = "#####"
            });


            contactList.Add(new Contact()
            {
                ID = "3",
                ContactName = "Gene | ",
                Address = "1234 right st | ",
                City = "AnyWhere | ",
                State = "State | ",
                Zip = "34221 | ",
                Birthday = "01/29/1970 | ",
                ImageSource = "#####"
            });


            lstContacts.ItemsSource = contactList;
        }


this info is for testing only...I would like to know why the info isnt displaying correctly.

any help is appreciated...

-InkedGFX
 
I expect to see the property values in the listbox....all I see is "MyBlackBook.Contact" on each line.the pipe is just a seperator!

-InkedGFX
 
I expect to see the property values in the listbox....all I see is "MyBlackBook.Contact" on each line.
You need to read this:

ListView, data binding and ItemTemplate - The complete WPF tutorial
the pipe is just a seperator!
If it's supposed to be a separator then it should be separating values, not be a part of the values. If you want a single String containing all values separated by a delimiter then create that separately and insert the delimiters then. What if you wanted to allow the user to edit the properties and then either you or they have to work around delimiters that shouldn't be there in the first place?
 
thank you for the help!

let me back up a bit.....the code I posted is only for testing purpose, the separator will not be in the actual string values...what I want do is bind a xml file to a listview.....which I hope the link you posted will help me do just that....I wasnt having any luck binding the xml file to the listview , so I thought I would try it the way I have done in the past which is create a class and store the values in the List<class> then fill the listview from the list<class> .....I think It is different in WPF tho......I will read the tutorial provided by the link and see if I can manage a solution...thank you

-InkedGFX
 
Back
Top Bottom