How to pass parameters to usercontrol's viewmodel through window's xaml? I am using MVVM pattern. I have tried creating a dependency property as below. But passing it in constructoe of viewmodel throws "nonstatic properties cannot be field initializers" exception. xaml.cs of usercontrol
public partial class SomeView : UserControl
{
SomeViewModel vm = new SomeViewModel(ForeColor);
public SomeView()
{
InitializeComponent();
this.DataContext = vm;
}
public Color ForeColor
{
get { return (Color)this.GetValue(ForeColorProperty); }
set { this.SetValue(ForeColorProperty, value); }
}
public static readonly DependencyProperty ForeColorProperty = DependencyProperty.Register("ForeColor", typeof(Color), typeof(SomeView ));
}
and this is how I am calling the user control
<local:SomeView ForeColor="{Binding Foreground}"/>
Foreground is a property of type System.Drawing.Color