Link to home
Start Free TrialLog in
Avatar of chuang4630
chuang4630

asked on

How to bind the property in nested user control in WPF MVVM?

I have implemented a basic user control: UCComboTextBox.  It consists three fields:
1. Title (Textblock)
2. TextValue (Textbox)
3. Desc (Textblock)

Then I implemented a user control MyServerView containing two basic user controls plus a checkbox chkDefault.

I have a View Model MyServerViewModel, corresponding MyServerView. MyServerView contains two properties:
1.  Server of MyServerType
2.  ServerList of List<MyServerType>

MyServerType contains three properties:
1. ServerName (string)
2. ServerLocation (string)
3. IsDefaultServer (bool)

The question becomes:

1. Do I need to create view model for the basic user control UCComboTextBox?
2. How do I bind the Text Value (in MyServerView) to Server.ServerName, Server,ServerLocation and Server.IsDefaultServer?

Thanks a lot in advance.
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Your datacontext object is "MyServerView"  which you are going to bind.

In the xaml you give the path while binding { MyServerType.ServerName } to bind to a label or textbox control.
ASKER CERTIFIED SOLUTION
Avatar of chuang4630
chuang4630

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chuang4630
chuang4630

ASKER

I have figured it out.