mvvm

WPF - OnPropertyChanged for a property within a collection

In a view model, I have a collection of items of type "ClassA" called "MyCollection". ClassA has a property named "IsEnabled". class MyViewModel { List<ClassA> MyCollection { get; set; } class ClassA { public bool IsEnabled { get; set; } } } My view has a datagrid which binds to MyCollection. Each row has a button whose "I...

Silverlight Unit Testing (databinding, MVVM)

Hi all, How would you suggest I write a unit test to check that a UI object is bound to a particular named property in my ViewModel? Thanks, Mark ...

Silverlight UserControl and MVVM

I have a very similar issue as described in this post. I have a UserControl to encapsulate an address. This contains a number of basic controls, mostly textboxes. I then have backing dependecy properties in the code-behind for each property... #region Line1 /// <summary> /// Gets or sets the Line1. /// </summary> pub...

How do I attach commands to the checking and unchecking of a CheckBox?

In my ViewModel I have two commands: ICommand ExecuteMeOnCheck { get; } ICommand ExecuteMeOnUncheck { get; } I wish to attach these commands to a CheckBox and have one of them execute when it is checked and the other execute when it is unchecked. What's the best way to achieve this without cluttering the View with code-behind? ...

Does MVVM violate DRY?

It seems that ViewModels that I make look suspiciously like other classes and they seem to require a lot of code repetition, e.g. in a current project I have: SmartForm: Model that represents a data form to fill in, has properties: IdCode Title Description collection of SmartFormFields etc. SmartFormControlView View SmartFormControlV...

How do I bind a StackPanel to my ViewModel?

In my view I have this: <TextBlock Text="{Binding Title}"/> which binds to my ViewModel's Title property and this is straightforward and works well: private string _title; public string Title { get { return _title; } set { _title = value; OnPropertyChanged("Title"); } } However my Vi...

Should my ViewModel have an ObservableCollection of Views or ViewModels?

I'm trying to understand the basic MVVM design approach when using ItemsControl by binding it via DataTemplates to ObservableCollections on the ViewModel. I've seen examples that bind to ObservableCollections of strings, Views, and ViewModels. Binding to strings seems to be only for demos, it is the binding to "ViewModels that contain ...

How to bubble up changes in my ViewModel hierarchy?

My MainView.xaml contains my SmartForm View: <Grid Margin="10"> <views:SmartForm/> </Grid> the SmartForm view loads an ItemsControl <Grid Margin="10"> <ItemsControl ItemsSource="{Binding DataTypeViews}"/> </Grid> which is an ObservableCollection of DataTypeViews: List<FormField> formFields = new List<FormField>(); ...

How would you go about using MVVM in Windows Forms?

Im trying to introduce the pattern to my team here in my company, but the bosses are reticent about going with WPF, cause they argue everyone has Windows Forms skills but no body has put its feet in WPF land yet, which is quite reasonable I guess. Yet the project would benefit from MVVM a great deal, I guess ...

WPF databinding binding error notification

OK, working on WPF(using MVVM) and came across a question, want some input. I have a simple class like below(assume I have IDataErrorInfo implemented): public class SimpleClassViewModel { DataModel Model {get;set;} public int Fee {get { return Model.Fee;} set { Model.Fee = value;}} } I then try to bind to it in xaml: <TextBox Te...

MVVM-pattern for a Paint-like WPF-Application?

Hi girls and guys! I'm currently in the planning phase for a project of mine. I thought about using the MVVM-pattern for my application for testability, maintainability etc. I have only started to get my head around MVVM but there is one thing that I just can't figure out in the context of my planned application. My application aims t...

MVVM Inheritance With View Models

I am wondering about how to approach inheritance with View Models in the MVVM pattern. In my application I have a Data Model that resembles the following: class CustomObject { public string Title { get; set; } } class CustomItem : CustomObject { public string Description { get; set; } } class CustomProduct : CustomItem { ...

MVVM: CollectionView in ViewModel or CollectionViewSource in xaml?

I'm developing a WPF application using the MVVM pattern and I need to display a list of items in a ListView (with filtering), with the fields of the selected item displayed in a Master/Detail view. I'm torn between the following two ways of doing this: Exposing a CollectionView in my ViewModel, and binding to this. Exposing a plain ILi...

Anybody knows how to test ICommand properties using Silverlight UT framekwork?

I download command behavior from web and have implemented in my silverlight project. Now I am trying to figure out how to unit test ICommand properties. I know lots of people are working on this, so if you have a good simple example of unit testing ICommand, please let me know. Thanks Dev ...

Programmatic databinding

How how do you do this in c#? <TextBlock Text={Binding MyProperty}/> Assume the DataContext is set to a class of Type MyClass ...

Hooking up the ViewModel to the View in Silverlight

I can see two ways to hook up the ViewModel to the View. One is in XAML and the other thru dependancy injection in the code behind. Which method is more preferable? I prefer the xaml method because I don't want any code in the code behind at all, but is there any issues with one over the other? <navigation:Page x:Class="MyNamespace.MyV...

MVVM for winforms

Should MVVM be used for WinForms? If so, what is the advantage over using MVP? ...

MVVM: Binding to List IsSelected while tracking IsSynchronizedWithCurrentItem

I'm tracking ListView selection changes in an MVVM design by binding to IsSelected. I also need to track the current item by enabling IsSynchronizedWithCurrentItem. I find that when I have two ListView binding to the same collection I get the InvalidOperationException: "Collection was modified; enumeration operation may not execute." ...

How big should your WPF app be to start using MVVM

Recently there have been a lot of move towards MVVM framework due to the nature of WPF development. I am making a pretty small application, which might grow a little over time. I am curious to know, what sized application should benefit from a MVVM implementation. For example .. has to have 15 user screens to be beneficial or something l...

I have some questions about MVVM pattern

Hello, My name is Jesús from Spain, I'm a .NET developer and I just discovered this great web few days ago. I have some questions about MVVM pattern and I will be glad if you can answer they. I started WPF 3 months ago and I learned the MVP pattern. MVP is so good because you can structure the app so well. I started seeing the mvvm pa...