mvvm-light

CommandManager.InvalidateRequerySuggested does not cause a requery on CanExecute in MVVM-Light

被刻印的时光 ゝ 提交于 2019-12-21 04:14:05
问题 I am using MVVM-Light RelayCommand private ICommand myRevertCmd; public ICommand Revert { get { if (myRevertCmd == null) { myRevertCmd = new RelayCommand(RevertExecute, CanRevertExecute); } return myRevertCmd; } } private void RevertExecute() { searchType = SearchType.Revert; SearchStart(); } private bool CanRevertExecute() { return isRevertEnabled; } I have some code that changes the value of isRevertEnabled but the linked button does not change. After some searching I found that you can use

Looking for simple MVVM Light example

妖精的绣舞 提交于 2019-12-20 09:20:03
问题 I'm trying to learn MVVM Light and am looking for a good basic example that shows a model and how to load different views. The template I see after downloading MVVM Light has no models and only one view. (http://www.galasoft.ch/mvvm/creating/) Other things I've found are more complex and a bit confusing when all I want to see are the basics. Thanks. 回答1: I have found this example helpful: http://apuntanotas.codeplex.com/ 回答2: I have personally found these to be quite useful, though they also

MVVM messaging or events or what other option out therer?

最后都变了- 提交于 2019-12-20 05:47:13
问题 I have a menu in MainViewModel, now on selection of a particular menuItem I wanted to update data of a view which is already loaded. i.e. although there's an instance of that viewModel in MainViewModel, when I try to invoke the method thru that instance and change the data property, it doesnt show the changes in the view. Whereas same changes occur when I invoke that method through relay command using a button on that viewModel's view. Now its like I need to invoke relay command of that

MVVM light: Pass object from view to viewmodel

ぃ、小莉子 提交于 2019-12-20 03:25:23
问题 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

RelayCommand from lambda with constructor parameters

时光总嘲笑我的痴心妄想 提交于 2019-12-19 21:48:32
问题 If, in a XAML file, I bind a Button to "Command" from the following class, then clicking the Button does not cause DoIt to be executed: class Thing() { public Thing(Foo p1) { Command = new RelayCommand(() => DoIt(p1)); } private DoIt(Foo p) { p.DoSomething(); } public ICommand Command { get; private set; } } However, it does work if I initialize a field from p1 and pass the field as a parameter to the method call inside the lambda: class Thing() { private Foo field; public Thing(Foo p1) {

WPF Zoom Canvas Center on Mouse Position

别来无恙 提交于 2019-12-19 11:46:16
问题 <utils:ScrollViewer x:Name="ImageViewer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Row="2" CurrentHorizontalOffset="{Binding ScrollHorizontalValue, Mode=TwoWay}" CurrentVerticalOffset="{Binding ScrollVerticalValue, Mode=TwoWay}" > <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewMouseWheel"> <cmd:EventToCommand Command="{Binding MouseWheelZoomCommand}" PassEventArgsToCommand="True"/> </i:EventTrigger> <i:EventTrigger EventName="ScrollChanged"> <cmd

MVVMLight UserControl View Model-Create new Instance of User control for each view

三世轮回 提交于 2019-12-19 11:33:39
问题 I have a user control of list of Patients which I use in other Views. However when I choose one of the Patients, the selection is propagated to all the views containing an instance of the user control. How can I make each view instantiate a new instance of the user control for each view? I am using c# 回答1: Guessing from what you stated, I'd assume that you returning a static instance of you PatientViewModel from you locator. To solve this make sure that when the property is called a new

MVVM RelayCommand CanExecute

僤鯓⒐⒋嵵緔 提交于 2019-12-19 06:31:20
问题 I'm implementing an RelayCommand with an execute and an canExecute part. The RelayCommand works when it is without the canExecute part, however when I add the canExecute part, the command locks the button. The RelayCommand only checks whether or not the button can be executed as long as the CanExecute part is true. Once the canExecute part becomes false, the button can no longer be clicked, even if it is supposed to. How do I make sure that every time I click on the button it controls whether

Best Practice to open a New Window in MVVM Light with Parameters

╄→гoц情女王★ 提交于 2019-12-18 22:33:01
问题 I am fairly new to mvvm and mvvm light, but I think I understand the general idea of it. What I don't understand is if I want to open a new window, but that window needs data from the caller what is the best practice to get that data to the new window? If I pass the data to the constructor then that means I need code in the code behind to pass it to the view model. I can't use messaging, because it isn't basic data. 回答1: One popular choice is to use a service class that will create a view

Confirmation when closing window with 'X' button with MVVM light

穿精又带淫゛_ 提交于 2019-12-18 18:04:17
问题 I am using WPF and MVVM Light framework (I am new in using them). I want to do the following: When the user click on the 'X' close button, I want to display a confirmation window if whether he wants to exit the application or not. If yes, the application closes If no, nothing happens and he can still use the application as per normal So far, I have this: In MainWindow.xaml.cs: public MainWindow() { InitializeComponent(); Closing += (s, e) => ViewModelLocator.Cleanup(); } In ViewModelLocator