I would like to use the x: Name binding to enable property binding in nested user satellite controls through the Caliburn.Micro conventions.
The user interface for our views is pretty standard. We have a satellite project that contains user controls that are then used to compose the user interface in our views, as shown below:
<UserControl x:Class="Company.CompanyView" ...> <StackPanel> <customControls:CompanyNameControl /> <customControls:CompanyAddressControl /> .... </StackPanel> </UserControl>
The ViewModel for this view provides properties that will be bound by the components that make up these user controls.
class CompanyViewModel : ... { public string CompanyName { get; set; } public string CompanyAddressNo { get; set; } public string CompanyAddressStreet { get; set; } ... }
User controls are usually simple, but they are reused in many different views. Here is an example of what might look like:
<UserControl x:Class="CustomControls.CompanyNameControl ...> <StackPanel Orientation="Horizontal"> <TextBlock Text="Company Name: " /> <TextBox x:Name="CompanyName" /> <TextBox Text="{Binding CompanyName}" /> </StackPanel> </UserControl>
My understanding is that in Caliburn.Micro, the x: Name convention style binding only works if there is a ViewModel for the view. In this case, the UserControl is not, itself, a View. It was used to create the presentation.
Is there a way to enable binding to the ViewModel for the view on which the nested UserControl satellite is composed?
source share