/// <summary> /// This method should be the only way of changing the visual state of the control. /// </summary> /// <param name="updateFunc">This delegate receives current view state and returns updated state.</param> public void UpdateViewModel(Func<MyCustomViewModel, MyCustomViewModel> updateFunc) { lock (_viewModelUpdateLock) { var currentViewModel = _currentViewModel; var newViewModel = updateFunc(currentViewModel); if (newViewModel != currentViewModel) { _currentViewModel = newViewModel; } } }
public ActionResult Index(string anyParameter) { ViewBag.MyCustomProperty = "Some Value"; var model = new MyCustomViewModel { Property1 = anyParameter, Property2 = Localization.GetString("LocalizedValue") }; return(View(model)); }
public MyCustomControl() { DataContext = _currentViewModel = new MyCustomViewModel(); CompositionTarget.Rendering += CompositionTargetOnRendering; }