mvvm

MvvmLight EventToCommand and WPFToolkit DataGrid double-click

Trying to figure out how to use EventToCommand to set a datagrid double click handler for rows. The command lives in the viewmodel for each row. Just that much out of my experience, since I haven't used interactions yet. Thanks. I would have used mvvmlight tag, but I don't have high enough rep yet to make new tags. ...

Setting WpfToolkit datagrid column editing style.

Hi, How to make a single datagrid column editable if a particular condition is true? I'm using MVVM pattern in my application. Model :: public class Book : INotifyPropertyChanged { public int BookId {get; set;} public string Title {get; set;} public string SerialNumber {get; set;} public bool CanEditSerialNumber...

Validate data binding in XAML in compile time

I’m working on WPF based application. Environment is VS2008 SP1 with .NET 3.5 SP 1. In our development we are using MVVM pattern widely. I.e. application developers write Models and ViewModels (C#), then UI developers will write Views using WPF Binding (XAML). Application developers also write unit tests on top of ViewModels. We are u...

What is the best practice for handling exceptions when using command binding in WPF?

I am using the MVVM pattern for a WPF application. In several places I bind commands to input elements in the views as in the following XAML: <Button Command="{Binding TheClickCommand}" >Click</> What is the best practice for handling exceptions thrown when the command is executed in my viewmodel - i.e. what is the best way to inform...

What’s the difference between a ViewModel and Controller in ASP MVC

What are the responsibilities of one vs the other? What kind of logic should go in one vs the other? Which one hits services and databases? How do I decide if my code should go in the viewmodel or the controller? for the record, I am using asp mvc ...

WPF MVVM combobox update problem

Hi everybody! I 'm going mad!! Created a "MainVM" (VM stands for ViewModel) in which there is defined a SelectedItem of type "EditVM". There is also another property (let's call it) excavations (this is an app for archaeologists) and its corresponding excavationsCollectionView (hope the type is clear, to not get into details). This e...

WPF: how to signal an event from ViewModel to View without code in codebehind?

Hi, I have quite simple (I hope :)) problem: In MVVM, View usually listens on changes of ViewModel's properties. However, I would sometimes like to listen on event, so that, for example, View could start animation, or close window, when VM signals. Doing it via bool property with NotifyPropertyChanged (and starting animation only whe...

Binding WPF TreeView with generic viewmodel

Hi, I have a usercontrol which contains a TreeView control. I am using MVVM pattern. I want to reuse this user control in different windows, each time binding the usercontrol to a different datacontext. <UserControl Name="UserControl1".......> .............. <TreeView ItemSource={Binding ...}...> <Hi...

Are WPF related properties inside a ViewModel a violation of MVVM best practices?

Here is an example case to elaborate: I am dynamically creating a simple Bar Graph using an ItemsControl in my View and binding the items to a collection of BarViewModels (each containing percentage a value) in my BarGraphViewModel. Each bar should have a different color. The colors should be chosen from a collection e.g. {Color1, Color...

How do I bind a TreeView node to a specific view in an Explorer-like UI?

I'm sure there is a simple answer to this but I can't seem to find it. Most examples for binding TreeView nodes are about using a ListView to show the node's details. In the scenario I am working on I've got a TreeView data bound to an Xml document using a simple MVVM pattern. As each node is selected in the TreeView I want to show a dif...

Model is updated by a background thread, how to get the changes to the ViewModel?

I have a model that updates itself in the background. Currently I'm using INotifyPropertyChanged on the Model, but I've been told thats a bad idea as the model should be UI independent. Is there a prefered pattern for updating the ViewModel when the Model changes in the MVVM design pattern? ...

Handling wpf control events in the ViewModel

Is there an alternative to Attached Command Behaviour for handling events like DataGrid's MouseDoubleClick event, or TextBox's LostFocus event in the ViewModel ? e.g., View:: <Window ........ DataContext="......."> <TextBox LostFocus="{Binding Command1}" /> <! -- or --> <WpfToolkit:DataGrid...

Changing XamDataGrid selection strategies in the ViewModel

Hi all, I have a ViewModel with a boolean MultipleSelections property and a DataView FoundData property. My view contains an Infragistics XamDataGrid bound to the FoundData property and SelectionTypeRecord is set to Extended (or it is not set and defaults to Extended). I want to be able to change the SelectionTypeRecord to Single when ...

MVVM ListBox controlling a Content Control

I've been going round in circles with this for a couple of days, and I'm hoping a WPF guru can see where I'm going wrong. I'm setting CurrentViewModel in code. The Selected item of my ListBox and the Content of my ContentControl bind correctly. But when changing the selected item in the Listbox via the UI the CurrentViewModel is being ...

WPF Bind Textbox IsEnabled to Listbox SelectedItem

Hi everybody! Using MVVM style i succefully bound an ObservableCollection to a listbox, showing up the values as radiobuttons. The control behaves exactly as expected. Now i have an issue regarding some textboxes bound to this listbox: i want whenever the SelectedItem in the listbox is equal to a specific value (e.g. 'ValueForEnabled')...

What is the accepted pattern for WPF commanding in MVVM?

I'm working on a WPF app and I understand the command pattern pretty well, but I've found that there are several different implementations of the command pattern for MVVM. There's Josh Smith's implementation in his WPF sample app, the DelegateCommand from Prism, and the CommandBindings implementation. My question is, what is the general...

Animation with MVVM pattern

Hello, What is the best way to trigger an animation while using the MVVM pattern? More specifically, I have a form which has several fields. When a user click's the save button, I would like to show an animation. I have been able to achieve this by exposing a property ShowMessage and setting it to True and a DataTrigger picks up this va...

Silverlight 3 LoadedEvent routed to ViewModel

My client is trying to hook to a usercontrols Loaded Event in the View Model. Basically they want to know when the controls loaded event triggers inside the view model. They are looking for a way to do it without code behind the xaml. Is this even feasible. I am looking into whether I can route the loaded event to the viewmodel in th...

Popup vs. Visibility toggle

I have a couple of views that I display as overlays on the main window by binding the visibility to a boolean property in my ViewModel. The main window looks something like this: <Grid> <vw:MainContentView/> <!-- Overlays (normally invisible) --> <vw:NotificationsView/> </Grid> ...

PRISM View Injection inside ItemsControl

UPDATED (12/17/2009): Now reflects latest progress I've made. This is the first application that myself and a co-worker are developing using Prism and MVVM in Silverlight 3.0. I am working on a shell/framework for the project that will have a list of "plugins" that can be added to a "workspace". The plugins are registered with a WorkS...