System.Windows.Controls.ViewModelAttribute.SetViewModel C# (CSharp) Method

SetViewModel() public static method

Sets the view model instance attached to the specified control. The view model is also used as the DataContext assigned to the control.
public static SetViewModel ( System.Windows.Controls.UserControl userControl, object value ) : void
userControl System.Windows.Controls.UserControl The control to associated the view model with.
value object The view model instance.
return void
        public static void SetViewModel(UserControl userControl, object value)
        {
            userControl.SetValue(ViewModelProperty, value);
            userControl.DataContext = value;
        }