I’m quite new to Caliburn.Micro, so I guess this has a simple answer (or at least I hope it has :))
I have a ViewModel with a property called ConnectedSystem that has a sub-property called Name.
In my View, I have the following XAML (excerpt):
<StackPanel Orientation="Horizontal">
<Label Content="Name:" />
<TextBlock x:Name="ConnectedSystem_Name" />
</StackPanel>
This works just fine, and the name is shown in the TextBlock as expected. However, ConnectedSystem has around 10 properties that should be displayed, and I don’t want to copy-paste the XAML above 10 times inside my view. Instead I want to extract that XAML as a UserControl where I can set the LabelText and Text as properties.
I tried this, but I’m not sure how I can get Caliburn.Micro to pass the ConnectedSystem_Name into my UserControl automatically.
It might be a better way than using a UserControl here also, so the question is basically: What is the best way of putting this shared XAML as it’s own control, and still be able to use Caliburn.Micros binding.
Caliburn.Micro doesn’t deal well with automatically linking multiple items to a single control. However you don’t have to rely on the automatic binder, you can use a plain old wpf binding instead.
A
UserControlis the way to go here. In the code you can add two DependencyProperties,LabelTextandText.Then in the XAML for your UserControl, bind to the new properties.
Where you use this control you can now set the LabelText and Text values in XAML. So on your main view add the control, and bind
LabelTextandTextto the properties in your ViewModel.