mvvm-light

MVVM light: Pass object from view to viewmodel

孤街醉人 提交于 2019-12-02 01:36:41
I 've recently started working with WPF using MVVM light and I have the following (simple scenario). MainWindow contains a listbox of elements. When one is selected and the button is clicked, I fire a command: ReservoirViewerCommand.Execute(null); On the viewmodel class I instantiate the command and send a message with the selected object: ReservoirViewerCommand = new RelayCommand(OpenReservoir); private void OpenReservoir() { Messenger.Default.Send(new LaunchShowReservoirMessage(){Reservoir=SelectedReservoir}); } where: class LaunchShowReservoirMessage:MessageBase { public Reservoir Reservoir

EventToCommand missing on MVVM Light

别等时光非礼了梦想. 提交于 2019-12-02 01:10:42
This helpful class seems to be gone from the latest MVVM Light build, any idea why or how to work around it? I'm using MvvmLightLibs.5.0.1.0, was definitely there on MvvmLightLibs.4.1.27.0. So this question is not related with one EventToCommand Missing For Windows Phone App Environment: VS2013, WP8.0 Eventually, I found the EventToCommand class on Galasoft.MvvmLight.Platform. I guess the assembly change makes sense being a multi-platform framework. xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform" <i:Interaction.Triggers> <i:EventTrigger EventName=

Pass whole row as parameter of DataGridTemplateColumn Hyperlink

白昼怎懂夜的黑 提交于 2019-12-01 22:52:20
Is it possible to pass a whole row as a parameter for the Hyperlink of DataGridTemplateColumn? <my:DataGridTemplateColumn Header="Name"> <my:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock> <Hyperlink Foreground="Black" TextDecorations="None"> <Run Text="{Binding Name}" /> </Hyperlink> </TextBlock> </DataTemplate> </my:DataGridTemplateColumn.CellTemplate> </my:DataGridTemplateColumn> Hard to tell what you are trying to achieve but a ComandParameter binding without a value should give you the row eg <Hyperlink Foreground="Black" TextDecorations="None" CommandParameter="{Binding}"

MVVM bind RelayCommand CanExecute to a Property?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 22:42:31
I have a Timer and three buttons to control it: Start, Stop, and Pause. Each button is bound to a RelayCommand. I have a TimerState property of type enum TimerState . (This is useful for setting various GUI elements.) Is there a way to somehow bind the RelayCommands' CanExecute functionality to the TimerState property? Currently, I have 3 methods that look like this: private bool CanStartTimer() { return (TimerState == TimerState.Stopped || TimerState == TimerState.Paused); } In the TimerState setter, I call StartTimerCmd.RaiseCanExecuteChanged(); Is there a better way bind the CanExecute

How to interact with UI elements when using MVVM/MVVMLight in a WPF app

陌路散爱 提交于 2019-12-01 21:29:51
问题 Based on my code below, I want to be able to change the background color of a Button 2 when Button 1 is clicked. XAML File <Grid> <Button x:Name="Button1" Content="Button 1" Command="{Binding Button1Command}"/> <Button x:Name="Button2" Content="Button 2"/> </Grid> ViewModel File public class MyViewModel : ViewModelBase { public ICommand Button1Command{get;private set;} public MyViewModel(){ Button1Command = new RelayCommand(() => button1_Click()); } private void button1_Click() { Console

MvvmLight SimpleIoc and multiple concrete implementations

偶尔善良 提交于 2019-12-01 21:14:58
问题 With SimpleIoc I'd like to register multiple implementations of IProvider , something like: SimpleIoc.Default.Register<IProvider, Provider1>(); SimpleIoc.Default.Register<IProvider, Provider2>(); So I can do: var providers = SimpleIoc.GetAllInstances<IProvider>(); Is there a way to do something like this? If I try it as is I get that there is already a class registered for IProvider . 回答1: You can do it by implementing a base class and using keyed registrations: public interface IProvider { }

Referencing a merged resource dictionary in windows phone seven failing

自作多情 提交于 2019-12-01 20:45:15
I am currently building a WP7 app using the MVVMLight framework. I would like to add a resource dictionary to my app.xaml, however when I do it fails. Here is a snipit from the app.xaml <Application.Resources> <!--Global View Model Locator--> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> <!--Merged Resource Dictionaries--> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> Because I am using a ViewModelLocator that

Unit testing with MVVM Light & DispatcherHelper

萝らか妹 提交于 2019-12-01 20:27:40
问题 I have a SL4 app that utilizes the MVVM Light Toolkit. Within a view model, I call a data service that retrieves data from an OData service. Within the VM, I am using the DispatcherHelper utility class (part of MVVM Light) to update the property on the VM from the data in the callback I pass into the data service. For instance, my view model method looks like this: public string CurrentUserLogin { get { if (string.IsNullOrEmpty(_currentUserLogin)) RetrieveCurrentUserLogin(); return string

How to interact with UI elements when using MVVM/MVVMLight in a WPF app

被刻印的时光 ゝ 提交于 2019-12-01 19:42:15
Based on my code below, I want to be able to change the background color of a Button 2 when Button 1 is clicked. XAML File <Grid> <Button x:Name="Button1" Content="Button 1" Command="{Binding Button1Command}"/> <Button x:Name="Button2" Content="Button 2"/> </Grid> ViewModel File public class MyViewModel : ViewModelBase { public ICommand Button1Command{get;private set;} public MyViewModel(){ Button1Command = new RelayCommand(() => button1_Click()); } private void button1_Click() { Console.WriteLine("Button 1 clicked"); // how can I change the background color of Button 2 here this.Dispatcher

Referencing a merged resource dictionary in windows phone seven failing

不想你离开。 提交于 2019-12-01 19:18:17
问题 I am currently building a WP7 app using the MVVMLight framework. I would like to add a resource dictionary to my app.xaml, however when I do it fails. Here is a snipit from the app.xaml <Application.Resources> <!--Global View Model Locator--> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> <!--Merged Resource Dictionaries--> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/> </ResourceDictionary