MVVM Light RelayCommand Parameters

I believe this will work: _projmenuItem_Edit = new RelayCommand<object>((txt)=>ProjEditNode(txt)); — EDIT — You’ll need to define your RelayCommand with the type as well: e.g. public RelayCommand<string> myCommand { get; private set; } myCommand = new RelayCommand<string>((s) => Test(s)); private void Test(string s) { throw new NotImplementedException(); }

Adding controls dynamically in WPF MVVM

If you really want to do mvvm , try to forget “how can I add controls”. You don’t have to, just think about your viewmodels – WPF create the contols for you 🙂 In your case lets say we have a SearchViewModel and a SearchEntryViewmodel. public class SearchEntryViewmodel { //Properties for Binding to Combobox and … Read more

MVVM Light & WPF – Binding Multiple instances of a Window to a ViewModel

Ok I put together a demo that should make this hopefully easier for you Download Link Functionality: 3 Windows in Total (MainWindow, ModalWindow, NonModalWindow) MainWindow has a TextBox you can type whatever you want into. 2 buttons on the top will open the Modal / NonModal Window accordingly Each window when opened will display the … Read more

How to open a new window using MVVM Light Toolkit

Passing a message from ViewModel1 to View1 means to use the messaging capabilities in the MVVM Light Toolkit. For example, your ViewModel1 could have a command called ShowView2Command, then it would send a message to display the view. public class ViewModel1 : ViewModelBase { public RelayCommand ShowView2Command { private set; get; } public ViewModel1() : … Read more

Handling the window closing event with WPF / MVVM Light Toolkit

I would simply associate the handler in the View constructor: MyWindow() { // Set up ViewModel, assign to DataContext etc. Closing += viewModel.OnWindowClosing; } Then add the handler to the ViewModel: using System.ComponentModel; public void OnWindowClosing(object sender, CancelEventArgs e) { // Handle closing logic, set e.Cancel as needed } In this case, you gain exactly … Read more

MVVM Light: Adding EventToCommand in XAML without Blend, easier way or snippet?

Suppose you use .NetFramework4: First add namespace: xmlns:cmd=”clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform” Syntax for the Loaded event. <i:Interaction.Triggers> <i:EventTrigger EventName=”Loaded”> <cmd:EventToCommand Command=”{Binding Mode=OneWay, Path=LoadedCommand}” PassEventArgsToCommand=”True” /> </i:EventTrigger> </i:Interaction.Triggers>

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

MVVM Light 5.0: How to use the Navigation service

Yes, MvvmLight introduced the NavigationService in their last version but they did’t offer any implementation regarding Wpf (you can use the Implemented NavigationService in WP, Metroapps, ..) but unfortunately not Wpf, you need to implement that by your self, here how i am currently doing it (credit) first create you navigation interface that Implements the … Read more

tech