Two Way Binding to AvalonEdit Document Text using MVVM

Create a Behavior class that will attach the TextChanged event and will hook up the dependency property that is bound to the ViewModel. AvalonTextBehavior.cs public sealed class AvalonEditBehaviour : Behavior<TextEditor> { public static readonly DependencyProperty GiveMeTheTextProperty = DependencyProperty.Register(“GiveMeTheText”, typeof(string), typeof(AvalonEditBehaviour), new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PropertyChangedCallback)); public string GiveMeTheText { get { return (string)GetValue(GiveMeTheTextProperty); } set { … Read more

Concrete examples of state sharing between multiple viewmodels (WPF MVVM)

A typical way to achieve this is to use a messenger to publish a CarSelected message that details the selected car. Zero or more ViewModels can subscribe to the CarSelected message. ViewModels that are interested in the currently selected car can listen for the message and then act accordingly. The messenger approach provides a clean … Read more

MVVM and IOC: Handling View Model’s Class Invariants

I’m not quite sure what the issue is, so I’ll use a simple and contrived example. Let’s say you have a CustomerListViewModel which lists a summary of each customer. When you select a customer, you want to display a CustomerDetailViewModel. This could take either a customer ID, or an ICustomer type which is populated previously … Read more

MVVM and nested view models

You are on the right track. The parent model would naturally contain a list of child models, e.g. a customer having multiple orders. When ParentViewModel is created and loaded by a third-party, it is passed a ParentModel. Then the ParentViewModel will: Assign the ParentModel to a local variable Create a ChildViewModel for each ChildModel by … Read more

prism vs mvvm light for wpf

I just moved a project from Prism to MvvmLight and it seems to work faster (very subjective). Both Prism and MvvmLight have Mediator realisation (IEventAggregator in Prism, IMessenger in MvvmLight). But IMessenger has more abilities (for instance, sending messages with tokens) compared to IEventAggregator and is much more convenient to use (see next item). MvvmLight … Read more

Implementing CollectionChanged

You have to add a PropertyChanged listener to each item (which must implement INotifyPropertyChanged) to get notification about editing objects in a observable list. public ObservableCollection<Item> Names { get; set; } public List<Item> ModifiedItems { get; set; } public ViewModel() { this.ModifiedItems = new List<Item>(); this.Names = new ObservableCollection<Item>(); this.Names.CollectionChanged += this.OnCollectionChanged; } void OnCollectionChanged(object … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)