mvvm

Making sure OnPropertyChanged() is called on UI thread in MVVM WPF app

In a WPF app that I'm writing using the MVVM pattern, I have a background process that doing it's thing, but need to get status updates from it out to the UI. I'm using the MVVM pattern, so my ViewModel knows virtually nothing of the view (UI) that is presenting the model to the user. Say I have the following method in my ViewModel: p...

Is there a mismatch between MVVM and the possibility to modify the View's component tree?

Having read all the StackOverflow entries regarding Model-View-ViewModel architecture along with most of the readily available resources on the net I have come to the conclusion that it is the de-facto standard for building SOLID Silverlight apps. I started to plan my next application using this architecture. One of the requirements for ...

How to build the ViewModel in MVVM not to violate the Single Responsibility Principle?

Robert Martin says: "There should never be more than one reason for a class to change". Let's consider the ViewModel class which is bound to a View. It is possible (or even probable) that the ViewModel consists of properties that are not really related to each other. For small views the ViewModel may be quite coherent, but while the appl...

Keyboard events in a WPF MVVM application?

How can I handle the Keyboard.KeyDown event without using code-behind? We are trying to use the MVVM pattern and avoid writing an event handler in code-behind file. ...

Can I get strongly typed bindings in WPF/XAML?

Using the MVVM-pattern you set the DataContext to a specific ViewModel. Now is there any way to tell the XAML the type of the DataContext so that it will validate my bindings? Looking for something like the typed viewdata in ASP.NET MVC. ...

WPF MVVM and Testing

I have been working on a WPF application and am using ModelViewViewModel. I have a number of events that come out of the view, that result in ViewModel activity. What is the resonable way to get these events raised from a UnitTest? For example, I want to simulate the drop event. I don't really want to build a stub view, just to raise...

Not the right <type>?

I'm confused. I've got a Silverlight project that currently runs and displays a list of servers from my mocked model (I am following the MVVM pattern). The interface is coded as follows: public class GetServersCompletedEventArgs : EventArgs { public Exception Error {get; set;} public IEnumerable<LicenseServer> Results {get; pr...

Silverlight MVVM linking model and view model

There are lots of great examples around on MVVM but I'm still confused. Lets say you have a CustomerModel and a CustomerViewModel. It seems there would be a Name property on the CustomerModel and one on the CustomerViewModel. The setter on the CustomerViewModel will set the CustomerModel Name property and then call the OnPropertyChange...

Silverlight MVVM header detail

So lets say i have an OrderModel and an OrderViewModel. I have the Supplier, Order Date, etc properties on both the ViewModel and the Model and they are linked up. Seen examples on this and seems straighforward enough, although somewhat duplicated in terms of writing setters/getters. Now what do I do with the OrderDetails? In my model I...

ICommand in MVVM WPF

Hello everybody, I'm having a look at this MVVM stuff and I'm facing a problem. The situation is pretty simple. I have the following code in my index.xaml page <Grid> <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <view:MovieView ></view:MovieView> ...

Attach ICommand in WPF UserControl

Hi everyone, I implemented a simple button with an image in it: <Button Command="{Binding ButtonCommand, ElementName=ImageButtonControl}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding ButtonImage, ElementName=ImageButtonControl}"/> <TextBlock Text="{Binding ButtonText, ElementName=...

How can a ViewModel know when data in a service is updated?

In my application, I've got several ViewModels that have a single service (repository, DAO, whatever), let's call it the WidgetService, injected into them. Let's say that one of these ViewModels is a listing of all of a users widgets. Another could be the ViewModel for editing/creating a single one of these Widgets. The user can vie...

Bind ViewModel Command to UI event in WPF

I have an Project object it has a Name Property. The ViewModel for project contains a ICommand called SaveCommand which persists in the database. I have a textbox in my UI that binds to Name <TextBox Text="{Binding Name}" LostFocus="??????" /> How do I bind my SaveCommand to the TextBox ecent LostFocus? So when the textbox loses foc...

MVVM Routed and Relay Command

What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ? ...

MVVM - what should contain what... what should create what

I'm having a right barney getting my head around how everything fits together using the MVVM pattern. It all seems quite simple in practice but trying to implement it I seem to be breaking various other rules that I try to code by. Just as a side note, I'm trying to implement the pattern using Flex, not Silverlight or WPF, so if anyone...

Prism 2 SL : Remove View from Region when button clicked

I am new to Prism and I am trying to determine a best practice for deactivating a view in a Prism 2 application -- when a user clicks a button on the view I want to deactivate the view. The view is executing a command when the button is clicked. The view model is receiving the command but the viewmodel does not have a reference to the ...

Best place to bring up new window in Model View ViewModel

I have an MVVM application. In one of the ViewModels is the 'FindFilesCommand' which populates an ObservableCollection. I then implement a 'RemoveFilesCommand' in the same ViewModel. This command then brings up a window to get some more user input. Where/what is the best way to do this whilst keeping with the MVVM paradigm? Someho...

How to further decouple this WPF example toward MVC, MVP, or MVVM?

I've decoupled events in this WPF application in the following way. What is the best way to continue decoupling? Shell.xaml: <Button x:Name="btnProcess" Content="Process" Margin="10"/> Bootstrapper.cs: public void Run() { Shell shell = new Shell(new Customer()); shell.Show(); } Shell.xaml.cs: public Shell...

WPF Context menu doesn't bind to right databound item

Hi! I have a problem when binding a command in a context menu on a usercontrol that is on a tab page. The first time I use the menu (right-click on the tab) it works great, but if I switch tab the command will use the databound instance that was used the first time. If I put a button that is bound to the command in the usercontrol it wo...

WPF MVVM ComboBox SelectedItem or SelectedValue not working

Update After a bit of investigating. What seems to be the issue is that the SelectedValue/SelectedItem is occurring before the Item source is finished loading. If I sit in a break point and weight a few seconds it works as expected. Don't know how I'm going to get around this one. End Update I have an application using in WPF using...