mvvm

ICommand Implementation Question

I am doing the following tutorial, to learn about the MVVM pattern in WPF. There's something I don't understand about the following seemingly partly given implementation of ICommand interface. In the code below the _canExecute variable is used as a method and a variable. I was thinking it's some event of some kind, but ICommand alrea...

Hierarchical data problems in MVVM.

Do you think this Model-ViewModel implementation is correct? Note that Stars (in the VM) is an ObservableCollection of VMs inside another one, and i feel like it decouples the VM from the M because when removing an element from Stars, i still have to delete it's model manually. Any ideas on how to improve this without using OnCollectio...

WPF - MVVM - What are the pros and cons of the various view creation techniques?

I've been using MVVM for the past two years and it has certainly evolved for the better since that time. As I read though the hundreds of MVVM articles and stackoverflow questions, I've noticed that there appears to be more and more articles that describe the view/viewmodel relationship and creation as ViewModel first or View first. Thes...

Dependency Property and ViewModel initialization problem

I am trying to add my own ItemsSource to provide a list of GraphViewModels to a chart. I dont think I have it quite right though, as when I create my first GraphViewModel and add it to the Graphs, my DP is updated, but OnGraphsCollectionChanged is not called. How is this supposed to work? If I add graphs to my VM property via a button ...

Databinding to functions in dynamically-loaded plugins

I have several MenuItems whose Commands are bound to my ViewModel. Until today, all of them execute properly. Now I have added a MenuItem whose ItemsSource is bound to an ObservableCollection. The point of this MenuItem is to enumerate a list of plugins so that the name of all plugins show up. Then when the user clicks on a plugin na...

How do you add a generic item to a ComboBox bound to a collection in WPF

I have a ComboBox in a WPF application that is bound to an ObservableCollection of Department objects in a C# ViewModel class. I want to use the combo box to filter another collection by department (And indeed it works for that now) The problem is that I want to add an additional option "All" to the top of the list. Is there a correct wa...

WPF ComboBox SelectedItem

Ok been working with WPF for a while but I need some help. I have a combobox like below: <TabControl> <TabItem Header="1"> <ComboBox ItemsSource="{Binding MyList}" SelectedItem="{Binding MyListSelection}"/> </TabItem> <TabItem Header="2"/> </TabControl> Whenever I move away from tab 1 and then come back to it the selection ...

WPF - Have a list source defined at runtime but still have sample data for design time

I have some ListBoxes in my WPF app. I would like to be able to view how the design looks with out having to run the app. But I still want to be able to bind to ItemsSource to my View Model. I know I saw a blog post on how to do this, but I cannot seem to find it now. To reiterate, I want dummy data at design time, but real data at ...

MVVM vs Data Virtualization

I have a TreeView that is bound to a tree of ViewModel instances. The problem is that the model data is coming from a slow repository so I need data virtualization. The list of sub ViewModel below a node should only be loaded when the parent tree view node is expanded and it should be unloaded when it is collapsed. How can this be impl...

Binding two UserControls to the same DataContext, or ViewModel?

I am working on a UserControl, which is composed of a Chart panel and another area which manipulates some of the chart data i.e. the chart controls (change color of graph, enable or disable stuff on the chart, etc.). I use a ViewModel to manage the chart and its data, but was thinking maybe it would be nice to make a separate usercontro...

Creating XML Editor and using WPF MVVM

Hi! I should make a XML editor on WPF with auto closing tags and highlight tags attributes and data. Now I use PreviewKeyDown event to check which key is pressed. For example when I press < the variable TagStart is set to true and everything typed after < is stored in StringBuilder variable and when > is pressed it generates a close tag....

Date picker doesnt allow edit and no null accepting

Hi Friends, Iam new to this forums. by the suggestion of my friend i came to know that this forum is very very good and we get a very good responses. iam new to .NET 3.5 , WPF, infragistics and MVVM. I have two calender controls and button control ( when clicking the button user see a list of events between the date range. We follow M...

What are the main drawbacks of using Presentation Model in code behind?

I am trying to prepare myself for being challenged with the question: "Why cant we just implement the presentation model in the code behind?" In fact I have worked on a project where we used a Presentation Model that was implemented in the code behind. It worked fairly well, we were even able to run unit tests on it. Yes you have a dep...

Exceptions are swallowed in my WPF application. How to force application to crash?

I am new to WPF, I am using VS2010 beta2, .NET 4.0. Throw new Exception("test") in my code simply swallows exception and application does not crash. This is not what I expect, I want the application to crash if unhandled exception occurs. Is there a simple way to achieve this? Also, neither Application.DispatcherUnhandledException no...

MVVM View Model DTOs

I have a WCF based application that uses the services to access repositories on the server side. I am passing DTOs from the server to the client and was wondering how best to make the DTOs part pf the view model. I have a workign example of just plain properties on the view model but was unsure how to deal with actual DTO objects and a...

How do I resolve this terminological confusion when refactoring existing code to use the MVVM pattern?

I'm struggling with a terminological conflict and can't figure out a good resolution. Maybe someone else has had this problem. I'm rebuilding an existing WinForms application to use WPF. I'll be using the MVVM pattern in my new application. My old application makes extensive use of ADO; specifically, I have Row objects that wrap Data...

Firing 1 usercontrol used for 3 different window at page load with different data

Hi Every one, Iam Divya working as developer. I had some issues. Hope there are many knowledged persons to solve my problem. We are following Model -View -View Model Pattern for WPF Window Project. I have an Window (contains only an XamData Grid) Which is complete User control. This User Control is used in 3 windows(Male Window, ...

Converting WPF / ADO.NET Data Services application to the MVVM pattern - Examples

I have a WPF application which was written in C#. This application hasn't been written with any particular design pattern in mind, but as I have learnt .NET I've realised that the MVVM model would be suitable. Thus, I'd like to start converting the code. This will be the first time I've used MVVM, and whilst I'm willing to get stuck in,...

Keeping the DI-container usage in the composition root in Silverlight and MVVM

It's not quite clear to me how I can design so I keep the reference to the DI-container in the composition root for a Silverlight + MVVM application. I have the following simple usage scenario: there's a main view (perhaps a list of items) and an action to open an edit view for one single item. So the main view has to create and show th...

In wpf treeview, how to redraw the nodes with their previous expanded values(using MVVM)

Hi to all, I am developing a wpf desktop app with strict MVVM pattern. Current my app is doing following things: Showing a Treeview with HierarchicalDataTemplate. User can expand or collapse Nodes. User can add add new Nodes(Drag n Drop + double click). Everytime a new Node is added Model is updated and Treeview ...