mvvm-light

MVVM Light : RelayCommand : define it lazy or in constructor?

試著忘記壹切 提交于 2020-01-01 12:16:25
问题 There are several examples on how to define a RelayCommand in the ViewModel : Option 1 ( lazy ): /// <summary> /// Gets the LogOnCommand. /// </summary> /// <value>The LogOnCommand.</value> public RelayCommand<LogOnUser> LogOnCommand { get { if (this.logOnCommand == null) { this.logOnCommand = new RelayCommand<LogOnUser>( action => { // Action code... }, g => g != null); } return this.logOnCommand; } } Option 2 (in constructor) /// <summary> /// Initializes a new instance of the <see cref=

How to have Multiple unique instances of ViewModel using MVVM Light?

女生的网名这么多〃 提交于 2020-01-01 05:50:55
问题 I am fairly new to following the MVVM pattern. I am using MVVMLight. I am wondering how have multiple unique instances of the ViewModel with MVVM Light. For exmaple I have an application that can open n number of windows. Each uses the same Viewmodel. I am curious in MVVM whats the best practive to give them there own instance. If I follow the MVVM Light example the ViewModeLocator will have only a static instance which each window will end up using. Thanks in advance. 回答1: You are not

Where are the MVVM Light snippets?

筅森魡賤 提交于 2019-12-31 17:58:11
问题 It seems that snippets of MVVM Light are not installed when we use Nuget to install MVVM Light Toolkit. Where can I find them ? 回答1: Snippets are available on GitHub. Download the code (upper right Clone or download button) and extract it. Use the Visual Studio Code Snippet manager (from the "Tools" menu) to import the snippets located in the Installer/InstallItems/Snippets/CSharp folder of the extracted code. 回答2: For anyone else who didn't find C# snippets in the download specified in the

How to handle ItemClick For Nested ListView In MVVM Pattern?

倖福魔咒の 提交于 2019-12-31 07:18:11
问题 Xaml code: <Page x:Class="DemoTestApp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:DemoTestApp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" xmlns:vm="using:ViewModels" > <Page.DataContext> <vm:TestViewModel/> </Page

WPF: OnCollectionChanged not firing

Deadly 提交于 2019-12-31 04:50:13
问题 Using VS 2102, .NET 4.0 and MVVM Light. I have the following code that reads items from an XML file into an ObservableCollection. I then want to update the Save button with a Converter if the collection changes (using an IsDirty flag) but the OnCodeCollectionChanged method is not being executed. The collection is properly displayed in the data grid and I can add new entries to the data grid but the OnCodeCollectionChanged method is never called. I am NOT trying to catch the change of an

WPF MVVMLight: Update DataGrid based on SelectedItem of another DataGrid

*爱你&永不变心* 提交于 2019-12-30 13:43:06
问题 Developing a WPF app using MVVMLight . My Model consists of an Attribute class and a DataSet class with an ObservableCollection<Attribute> property named Attributes . My MainViewModel has a DataSet property. In my MainView which has it's DataContext set to MainViewModel I have two DataGrids . One has it's ItemsSource binded to DataSet.Attributes which works fine: <DataGrid CanUserAddRows="false" AutoGenerateColumns="false" ItemsSource="{Binding DataSet.Attributes}"> //some DataGrid columns

How to use MVVM-Light with tokens?

橙三吉。 提交于 2019-12-30 01:31:13
问题 I see in the MVVM-Light package that I can send messages with tokens- what I need to do is send an object, with a message attached to that object- like Add, Edit, Delete whatever. What is the best way to send and to recieve this message? I think for send its just: Messenger.Default.Send(myObject, ActionEnum.DELETE); But in the receive: Messenger.Default.Register(this, ????, HandleMyMessage); What is the correct syntax? Thanks! 回答1: Here is a quick section of code for both the send and the

How to add Command Behavior in windows store 8.1 MVVM application

╄→гoц情女王★ 提交于 2019-12-29 04:01:48
问题 I want to invoke a command on TextChange event of new windows phone 8.1 AutoCompleteBox Control. I am using MVVM Light. 回答1: In new windows store 8.1 apps there is a new SDK Behavior SDK for adding behaviors in the application. it is not added by default you have to add this Extension in your project. below is how to add this extension in your project. install the Behavior SDK from the list. Now in your XAML page add following namespaces to InvokeActionCommand that is capable of invoking

Alternatives to Prism + MEF for modular MVVM apps [closed]

末鹿安然 提交于 2019-12-29 03:10:51
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . My team and I are beginning to plan the development of a modular application which will likely multi-target WPF & Silverlight. I

RelayCommand stops working after a while

拟墨画扇 提交于 2019-12-28 06:58:32
问题 I am facing some problems using GalaSoft's RelayCommand. I have a NextCommand property that works, but only several times. Afterwards, it stops working completely. You can try this out with the sample project: http://s000.tinyupload.com/?file_id=65828891881629261404 The behaviour is as follows: NextCommand : pops all items until the active index if there are less than 50 items left, pushes 1 new item marks new item as active BackCommand : moves the active index back by 1 position Steps to