mvvm

MVC / MVP / MVVM What the Heck?

I recently worked on a .Net WPF project to build a retail point of sale system where I used the MVP pattern for the first time. It took me a little while to wrap my head around the change of approach but once I did that I thought that the concept rocked! My question is this: what is the distinction between MVC, MVP and MVVM? If there is...

How to get the selected index of MVVM-bound radiobuttons?

I have an ItemsControl which is bound and set to an observablecollection in my viewmodel: <ItemsControl ItemsSource="{Binding AwaySelection}" > <ItemsControl.ItemTemplate> <DataTemplate> <RadioButton Content="{Binding AwayText}" ></RadioButton> </DataTemplate> <...

WPF design question (custom control or mvvm)

Here is the scenario: I have a visual that displays some data The data to the visual can come in one of two ways Via user input through the keyboard or mouse Via some backend source Both these data inputs can be of one of two forms Control data or Raw data for simple display Control data causes changes in the visual Raw data is sim...

Scope of View Models when using Service Locator Pattern in WPF app

Hi there, When using a Service Locator class to serve up ViewModels for your WPF pages to bind to. Should the ViewModels be Singleton scoped or Factory scoped? Is one generally a better idea for WPF applications?? I'm aware that in Silverlight, Singleton lends itself better to pages which are User Controls and are only moved into and o...

What is the "proper" way in WPF MVVM to bind a frameworkElement event to a viewmodel handler?

So here is my dilemma, I want to handle view events on my view model, trouble is, in order to add an event handler, my view has to have a code behind file and therefore a class attribute has to be set. I'm 99% sure this is a bad idea, and to be perfectly honest, i'm not even sure how to do it (other than the obvious x:Class="" part) Wh...

WPF Databinding not updating

Hi, I'm trying to change the content of a ContentPresenter to one of my View Model class. I manage to have it shown properly, once I change this content (property) from my model, it doesn't update the ui. The following lines link my view model classes to their respective ui (setting their data context automatically) : <DataTemplate...

using MVVM and WPF for a realistic visualizations

I currently need to create a visual representation of a ferry system that displays the actual ferries their position on the sea and the state of their cargo. The ferries contain trucks and the trucks contain cars. I need to display the actual trucks and their xy postion on the deck. When the ferries are loaded the postions of the trucks ...

How to get bind a (WPF or Infragistics) DataGrid to a List<List<string>> or List<string[]>?

I need to bind a collection of strings inside a collection of strings to a DataGrid (Infragistics). However, when I bind it like this: <DataPresenter:XamDataGrid x:Name="xamDataGrid" DataSource="{Binding TheCollection}"> to either this: public List<string[]> TheCollection or this: public List<List<string>> TheCollection I get t...

[MVVM] What is the way of updating a UI after a command?

Hello, I'm learning MVVM through a project and I got stuck on something simple. I have a button that updates a Listview. I have a command in the ViewModel that make the right things but I want to select the new row and get the focus on a textbox after I click the button. The question is: How do I update my UI after executing a command?...

Error window show modal in MVVM WPF

Hi guys I have implemented my MVVM error message as a message dialog that subscribes to error messages via a mediator class, so that other viewmodels can notify it if any errors occur. When an error occurs, I set the visibility attribute in the viewmodel to Visible, to display the error window. This is all bound in the Error window fro...

Josh Smith's MVVM Demo App: Add commands to MainWindowViewModel's command list

I have a question concerning Josh Smith's famous demo app on MVVM. I try building a "real" application around it to learn WPF. He creates this CommandsList in the MainWindowViewModel containing 2 Commands (create new and view all customers). This list is readonly (why? any particular reason?). I thougt it would be nice to add and remo...

MVVM with TreeView - add nodes

I am new to WPF, and I am trying to implement MVVM with TreeView according to an example. However, in addition to the functionality in the example I would like to be able to add nodes to the tree (i.e. add new child to a specific node in the tree during runtime). My question is, should the new nodes be added to (a) the model or to (b) t...

MVVM and Stateful commands - Good or bad idea?

Hi, I thought I'd post here in the hope that maybe someone with MVVM expertise would be able to offer opinions on whether the following is a good idea: I'm using Sacha Barber's Cinch MVVM framework, which includes Marlon Grech's SimpleCommand class. One thing this class doesn't have which some other alternatives have is a Text property...

Opening an about box using MVVM pattern

I'm working on a new WPF application and I'm trying to stay as close to the MVVM pattern as I can. My XAML files right now have no codebehinds, and all my interactivity is achieved using Josh Smith's RelayCommand class and commands in my ViewModel classes. This worked great until I started working on the housekeeping tasks, such as an ...

Localizing MVVM based WPF applications

What would be a good aproach to localize a MVVM based WPF allication that can change its language at runtime? Of course I could create a string property in the ViewModel for each and every string that is displayed somewhere in the View but that seems rather tedious to me. Is there a common approach/best practice for this? ...

Should the MVVM ViewModel perform type conversion/validation?

Hi We're just getting into MVVM in WPF. We have implemented our ViewModels with 'strongly typed' properties (int, double? etc.) that we bind to in the view. Type conversion works OK, mostly, and so entering data is simple enough. But we run into problems with validation. If, say, a non-numeric value is entered in a text box bound to ...

providing designtime ViewModel data for Blend and VS

In a MVVM based application, what options do I have to provide ViewModel data at design time, so our designers can actually see something in Blend3 (and VS 2008). How are you doing this? Can I utilize mc:ignorable for this somehow? ...

MVVM Exception Handling

I have a WPF Application that I have been trying to write in the MVVM style. If an Exception is thrown (like when a document is opened), I would like to display a MessageBox. Easy to do, but my code doesn't feel quite right because the MessageBox.Show call is in the ModelView. I thought that sort of thing is supposed to live in the Vi...

How to bind to a property of the ViewModel from within a GridView

I'm using the MVVM design pattern, and the DataContext of my View is set to a ViewModel. In my View, I have a ListView/GridView with ItemsSource bound to a DataTable. One of the GridViewColumns has a CellTemplate that presents a Button. I want the IsEnabled property of the button to be bound to the SelectButtonsEnabled property of my Vi...

WPF: hiding a tab item in a tab control thats bound to an observable collection

Heya I have a tab control bound to an observablecollection for dynamic tabs as follows: <TabControl ItemsSource="{Binding AllTabs}" SelectedIndex="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <TabControl.ItemTemplate> <DataTemplate> <!--.............. --> ...