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.
Who is Participating?
chuang4630Connect With a Mentor Author Commented:
You have to use either Parent or Level and relativePath to get this work

        <TextBlock x:Uid="tbkRequired" Name="tbkRequired" HorizontalAlignment="Left" VerticalAlignment="Top"  Margin="570,10,0,0" TextWrapping="NoWrap"  
                    Visibility="{Binding Path=RequiredFieldVisibility}"                  
                    FontWeight="Bold" FontSize="16" Foreground="Red"                    
            <TextBlock.ToolTip >
                <ToolTip DataContext="{Binding Path=PlacementTarget.Parent.Parent, RelativeSource={x:Static RelativeSource.Self}}">
                    <Grid Height="20" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Border BorderThickness="0" >
                            <TextBlock x:Name="rx" Height="20" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="10" Foreground="Red"
                            Text="{Binding Path=RequiredMessage}" />                                
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.
chuang4630Author Commented:
I have figured it out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.