WPF - Bind to selecteditem of listbox between user controls

Viewed 10955

I have two usercontrols, the first with a listbox that is bound to a list of Customers that displays some simple details for each customer.

The second user control I would like to be a more detailed view of whichever customer is selected in the listbox of the first usercontrol.

Is it possible to set up a binding in the second control to bind to the selected item in the first user control?

My List box:

            <ListBox Name="lstCustomer" ItemsSource="{Binding Customers}" >           
                <ListBox.Resources>

                    <DataTemplate DataType="{x:Type MyApplication:Customers}">
                       <Label Grid.Row="0" Content="{Binding Customer.name}" FontSize="14" FontWeight="Bold" Padding="5" />                             
                                <Label Grid.Row="1" Grid.Column="0" Content="{Binding Customer.telephone}" Padding="10,5" />                 
                            </Grid>
                        </Grid>

                    </DataTemplate>
                </ListBox.Resources>
            </ListBox>

Detailed view Usercontrol (So Far)

 <Grid x:Name="containingGrid" DataContext="{Binding ElementName=lstCustomers, Path=SelectedItem}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{Binding Customer.name}" FontSize="23"/>
        </Grid>

Thanks Greg

2 Answers
Related