When I use an UserControl I pass the data through DependencyProperties. My UserControls doesn't have ViewModels. UserControls only handle the passed data a very special way.
But if I have View that contains some Sub-Views I prefere to have for each Sub-View a own model. These model I'll bind through a property of the ViewModel of the MainView.
Some example:
UserControl1, Code behind:
public partial class UserControl1 : UserControl
{
public MyClass MyProperty
{
get { return (MyClass)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(MyClass), typeof(UserControl1), new UIPropertyMetadata(null));
public UserControl1()
{
InitializeComponent();
}
}
public class MyClass
{
public int MyProperty { get; set; }
}
And the usage in the view, XAML:
<Window x:Class="Sandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Sandbox="clr-namespace:Sandbox">
<Grid>
<Sandbox:UserControl1 MyProperty="{Binding MyOtherPropertyOfTypeMyClassInMyViewModel, Mode=TwoWay}" />
</Grid>
Hope this helps