mvvm

A MVVM pitfall using Master-Detail scenario

Either I do not see the solution or I found a pitfall in using MVVM. I have this sample Master-Detail: class Customer { int CustomerID {get;set} string Name {get;set} ObservableCollection<Order> Orders {get;set} } class Order { int OrderID {get;set} int Quantity {get;set} double Discount {get;set} } Lets assu...

What's new in .net 4 for MVVM?

Does .net 4 add anything new for working with MVVM? ...

Silverlight 4 RIA Services DDS to ViewModel-AutoComplete Selected Item Binding

I have an AutoCompleteBox that uses RIA DomainDataSource for the query to the server. I need to bind the AutoComplete.SelectedItem to the ViewModel.SelectedEmployee. They share the same DomainContext and data, but have different queries. When I try the following: ViewModel.SelectedEmployee = autoCompleteBox1.ItemsSource; I get the err...

What's the best way to handle navigation in a WPF application following the MVVM pattern?

I've seen this done inside of an event handler directly behind the .xaml file however it doesn't seem like this would follow the MVVM pattern: MainApplication.mainFrame.Navigate(new HomePage());. Is there a better way for handling navigation with the MVVM pattern perhaps in the ViewModel? or in the XAML? ...

How do I apply a ViewModel to the UserControl inside of a Page?

Doing something like this: <DataTemplate DataType="{x:Type vm:AllCustomersViewModel}"> <vw:AllCustomersView /> </DataTemplate> works in a ResourceDictionary for when I want to apply a ViewModel to a UserControl as root, but how do I the same thing when I have a UserControl inside of a Page? Would I create a ResourceDictionary for all ...

Fetching related data from database via sqldatareader and push into ViewModel/ViewModelCollections

Hello all, Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View with the CustomerOrderProductViewModel.cs: I have several controls like listbox,datagrid,etc.. to display those entities in my View. Those Entities shall be fetched sort of eager loading. That would mean I have 3 sqldatareader in ...

Handling fatal exceptions in ViewModel/Model

I have an application written using the M-V-VM approach. The data access is done in the Model. If a fatal error occurs here (for example, the connection to the data source is lost), and Exception is thrown. This Exception bubbles up to the ViewModel. However, because the original trigger of the data access was a data binding, WPF swall...

MVVM best practice to pass Dispatcher to the ViewModel

I suppose to be able to access the Dispacher that belongs to the View I need to pass it to the ViewModel. Bu the View should not known anything about the ViewModel so how do you pass it? Introduce an Interface or instead of passing it to the instances create a global dispatcher singleton that will be written by the View? How do you solve...

SL3 Nav framework + MVVM ligh

Hi All, Thanks for taking time to read through my question. Any guidance is really appreciated. I am using SL3 Navigation framework in my LOB application. I m currently using MVVM Light as the framework guidance. I have a datagrid consisting of employees and when the "user" clicks on "employee id link" in the datagrid, i am transferr...

How to set a value in a ViewModel from binding?

Kind of an odd question- if I'm thinking of this the wrong way please let me know. I am using an infragistics dock manager, which manages tabs as well. So I can create a TabGroupPane, and then add multiple ContentPanes, each of which has its own tab. In each content pane, I set my viewmodel: <ContentPane> <viewmodels:MyViewModelFor...

Switching views in a Silverlight Mvvm application

I have a View where the user can select "Basic Configuration" and "Advanced Configuration" from a radiobutton group. This view will then display one of two usercontrols (views): BasicConfigurationView and AdvancedConfigurationView. I can solve this by just hiding/showing the views when the user clik on the radiobuttons, but is there a be...

WPF Reverse Binding OneWayToSource

I have a custom control which has the following dependency property public static readonly DependencyProperty PrintCommandProperty = DependencyProperty.Register( "PrintCommand", typeof(ICommand), typeof(ExportPrintGridControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); publ...

MVVM Passing data to dialog View Model

Hi, I'm looking into using MVVM and while I understand it for the most part, there is one thing I can't get my head around. Imagine I have a View and ViewModel combination that show a list of foobars. When the user selects a foobar in the list and clicks the edit button I want the foobar to be shown in a popup dialog window so it can ...

WPF: Activate Trigger when a MVVM bound property changes

Hi, somehow I am going in circles here. Please forgive me if the answer to this question is obvious. I want to react to changed properties in the ViewModel in the View. When the properties (bool) change the View should start an animation (BeginStoryBoard). Actually in my application there are 4 of these properties each with its own nam...

What's the efficient way to search and filter ObservableCollection

I've a database consisting of about 1 million records. My application makes frequent incremental search on these records and filters the UI list. The scenario is more like the 'phone contact search'. Currently i'm following this: Load the data into List<myModel> in the DataSource Layer` Send it to MainViewModel Load List<myMod...

Multiple ListBoxes binding their SelectedItem to the same property in ViewModel - better way?

I have a WPF listview, and in one column the cell may contain one or more ListBoxes. When I right-click a ListBox I'm building a context menu where each item has a DelegateCommand. Currently I'm setting the command parameter to a SelectedListBox property on the page viewmodel itself as my delegate command needs to know which ListBox has...

Silverlight MVVM MEF ViewInjection

Hi all, since my title is buzzword compliant I hope I will get lots of answers to my question or any pointers to the right direction. OK what I usually do is have a ViewModel which contains a list of ViewModels itself. public class MasterViewModel { public ObservableCollection<DetailViewModel> DetailViewModels { get; set; } pub...

Binding a WPF ShortCut Key to a Command in the ViewModel

Hi, I have a WPF app that is using the MVVM pattern. Hooking up buttons to the VM is pretty straight forward since they implement the ICommand. I have a context menu that works similar. The next step is to create shortcut keys for the context menu. I can't figure out how to get the shortcut key invoke the Command. Here is an example: ...

Dealing with WPF objects inside ViewModel

Using the MVVM pattern creating WPF applications you have the ViewModel providing data to the View. I've met a situation where I find it reasonable to create WPF objects in my ViewModel, and the View fetches these and shows them. More specifically I have functionality for drawing where I need to store an InkPresenter in the end. I receiv...

Is this the best way to convert List<T> from models to ObservableCollection<T> in views?

In MVVM development I am constantly converting List<T> from my models to ObservableCollection<T> for my views. I looked around in .NET for a way to succinctly do this e.g. such as .ToList<> or .ToArray<> or .ToDictionary<> but couldn't find anything similar for ObservableCollection. Therefore I made the following extention method Conve...