c# - How to bind to a collection within a collection in WPF -


I am still in the initial stages of learning WPF and I have decided that easy to get contact browser app basic I am using an object from another application to add complexity to catch up with the principles.

So far I have successfully banned a list box control in a collection and is able to display contact names. In the middle of the screen I have a stackpanel with a custom controller that displays more details of the contact It all works wonderfully well that in addition to the fact that the object model for contact hides in the collection of phone answering field fields.

Am I bound object collection?

Here are some of my XML, the first main contact window:

  & lt; DocPanel width = "auto" height = "auto" margin = "8 8 8 8" & gt; & Lt; Border height = "56" horizontal alignment = "statch" vertical alignment = "top" borderline = "1" cornerradia = "8" dock panel Doc = "top" background = "beige" & gt; & Lt; TextBox Height = "32" margin = "23,5,135,5" text = "Search for contact here" FontStyle = "Italic" foreground = "#FFAD 9 595" fontisystem = "14" borderbrush = "lightgray" /> ; & Lt; / Border & gt; & Lt; ListBox x: Name = "Contact List" Dock Panel. Doc = "left" width = "192" height = "auto" margin = "5 4 0 8" itemsource = "{binding}" displaymemberpath = "full name" /> & Lt; Grid datacentext = "{binding element name = contact list, path = chosen item}" & gt; & Lt; Grid.RowDefinitions & gt; & Lt; RowDefinition Height = "1 *" /> & Lt; Roadfinion height = "0.125 *" /> & Lt; /Grid.RowDefinitions> & Lt; Local: Basic contact card margin = "8 8 8 8" /> & Lt; Button grid Rau = "1" x: name = "exit" content = "exit" horizontal alignment = "right" width = "50" height = "25" click = "exit" /> & Lt; / Grid & gt; & Lt; / DockPanel & gt;  

And here's XAML for BasicContactCard:

   & Lt; RowDefinition Height = "1 *" /> & Lt; RowDefinition Height = "1 *" /> & Lt; RowDefinition Height = "1 *" /> & Lt; /Grid.RowDefinitions> & Lt; TextBlock x: name = "companyfield" grid. Line = "0" width = "auto" horizontal align = "statch" vertical element = "statch" margin = "8,8,8,8" text = "{binding company}" fontweit = "bold" font seices = "15" /> & Lt; TextBlock x: name = "contactField" grid. Line = "1" width = "auto" horizontal alignment = "statch" vertical element = "statch" margin = "8,8,8,8" text = "{binding full name}" fontwight = "bold" /> & Lt; TextBlock x: name = "phoneField" grid. Line = "2" width = "auto" horizontal alignment = "statch" vertical alignment = "statch" margin = "8,8,8,8" text = "{binding phone}" /> & Lt; TextBlock x: name = "emailField" grid. Rows = "3" width = "auto" horizontal alignment = "statch" vertical alignment = "statch" margin = "8,8,8,8" text = "{binding valid email address}" /> & Lt; / Grid & gt; & Lt; / DockPanel & gt;  

In addition to the phone, all the elements of the Basic Contact Card are highlighted as attributes obtained from a contact archive object which is bound to exclude the phone located in the list box field. Those that can be said in C #

  contact c = contacList [i]; String val = c.ContactFields.Item ("phone", type fieldname. Alias);  

I hope that all makes sense! Any help or signs for resources will be appreciated!

Viv

Use the value converter to get the phone number.

XAM:

  & lt; UserControl.Resources & gt; & Lt; TestApp: PhoneNumberConverter x: key = "PhoneNumberConverter" /> & Lt; /UserControl.Resources> & Lt; Text block text = "{binding., Converter = static processing phone phone number notation}}" />  

Behind the code:

  Public class PhoneNumberConverter: IValueConverter {Public Object Convert (Object Value, Type Target Type, Object Parameter, System.Globalization.CultureInfo Culture) {Contact as C = Price; String Phone Nr = c.ContactFields.Item ("Phone", Field Name Type. Elias); Phone return; } Public Object Convertback (type object type, type target type, object parameter, system globalization. Culture info culture) {new non imulated expansion (); }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -