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

How do you select the right size icon from a multi-resolution .ico file in WPF?

I use simple Markup Extension for that: /// <summary> /// Simple extension for icon, to let you choose icon with specific size. /// Usage sample: /// Image Stretch=”None” Source=”{common:Icon /Controls;component/icons/custom.ico, 16}” /// Or: /// Image Source=”{common:Icon Source={Binding IconResource}, Size=16}” /// </summary> public class IconExtension : MarkupExtension { private string _source; public string Source { get … Read more

WPF Datagrid Row Editing “ENDED” event

private void dgrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { if (this.dgrid.SelectedItem != null) { (sender as DataGrid).RowEditEnding -=dgrid_RowEditEnding; (sender as DataGrid).CommitEdit(); (sender as DataGrid).Items.Refresh(); (sender as DataGrid).RowEditEnding += dgrid_RowEditEnding; } else Return; //then check if the newly added row is duplicated }

WPF BackgroundWorker vs. Dispatcher

The main difference between the Dispatcher and other threading methods is that the Dispatcher is not actually multi-threaded. The Dispatcher governs the controls, which need a single thread to function properly; the BeginInvoke method of the Dispatcher queues events for later execution (depending on priority etc.), but still on the same thread. BackgroundWorker on the … Read more

WPF Databinding thread safety?

Value changes fired by INotifyPropertyChanged are automatically marshalled back onto the dispatcher. (http://blog.lab49.com/archives/1166) Fire this event on any thread you like… Value changes fired by INotifyCollectionChanged are NOT reliably marshalled onto the dispatcher. (http://csharplive.wordpress.com/2008/09/11/wpf-data-binding-observablecollection-cross-thread-binding-support/) If you need to update an observable collection from a different thread, follow the advice in this link

How do you override the opacity of a parent control in WPF?

I was able to achieve something like this in pure xaml using a Brush to paint the main grids background. This way only parent grid will have its opacity set and its child elements won’t inherit it. <Grid x:Name=”LayoutRoot”> <Grid> <Grid.Background> <SolidColorBrush Color=”Black” Opacity=”0.5″/> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height=”0.333*”/> <RowDefinition Height=”0.333*”/> <RowDefinition Height=”0.333*”/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition … Read more