mvvm

Data bound WPF ComboBox with choices defined in XAML?

On my viewmodel I've got an int property and I want to expose it for editing with a ComboBox, with a limited set of choices, such as 16, 8, 4 and 2. Is there a way to specify the choices in the XAML, while still binding the value back to the viewmodel? I'd want to do something like this: <ComboBox SelectedValue="{Binding MyIntProperty}"...

Editing newly added row in Silverlight 3 DataGrid using MVVM

I am trying to use the Silverlight 3.0 DataGrid with the MVVM design pattern. My page has a DataGrid and a button that adds an item to the collection in the VM using a command (from the Composite Application Library). This works fine, and the new item is displayed and selected. The problem I can't solve is how to begin editing the row. ...

SilverLight - Binding a command to button within control template

I have a datagrid. Within that datagrid, I have bunch of column headers styles. Inside the control template of this style, there is a button. I need to bind a command to that button. Note that, there is also a TextBlock within the header style which I bind using element to element binding, as I will not have my viewModel in the header'...

Silverlight Label content binding problems

I'll preface this and say that I'm new to Silverlight development by about week so I'm most likely doing it wrong... Anyway I have a Label and a TextBox done up thusly in XAML: <dataInput:Label Target="{Binding ElementName=JobCode}" Height="18" HorizontalAlignment="Left" Margin="15,7,0,0" Name="lableJobCode" VerticalAlignment="Top" Wid...

Linq to SQL EntitySet Binding the MVVM way

Hi everybody! In a WPF application i'm using LINQ to SQL classes (created by SQL Metal, thus implementing POCOs). Let's assume i have a table User and a Table Pictures. These pictures are actually created from one picture, the difference between them may be the size, coloring,... So every user may has more than one Pictures, so the a...

Simple Event Handling in MVVM

Just wondering what people had for ideas on how best to handle events in a ViewModel from controls on a View ... in the most lightweight way possible. Example: <MediaElement MediaOpened={Binding SomeEventHandler} /> In this case we want to handle the MediaOpened event in a ViewModel. Without a framework like Prism, how would on...

Any MVVM frameworks work well with NavigationWindows?

I'd like to "throw away" the current version of a WPF application and move version 2 to a stable MVVM framework. The main concern I'm having is that I don't see much talk about MVVM frameworks and navigation (i.e., NavigationWindows and Frames). My current app relies heavily on Pages to present views to the user. I would prefer to kee...

MVVM ViewModel vs. MVC ViewModel

ViewModel is a term that is used in both MVVM (Model-View-ViewModel) and the recommended implementation for ASP.NET MVC. Researching "ViewModel" can be confusing given that each pattern uses the same term. What are the main differences between the MVC ViewModel and MVVM ViewModel? For example, I believe the MVVM ViewModel is more rich...

Silverlight MVVM: how to avoid polluting my model while still implementing "add new item" for my datagrid?

I have a DataGrid. Right now it's binding to an ObservableCollection<Foo> in my model just great. But now I want to implement a user-friendly way to add a new item to the datagrid. It seems like I'll need to modify Foo to inherit from IEditableObject and INotifyPropertyChanged, which is kind of icky from a MVVM perspective in my mind---...

RelayCommand not firing on MenuItem click WPF MVVM

Hi all, I have menu item on my WPF form that runs a import routine, I have bound the command property to a ICommand property in my view model but for some reason the method won't fire. This is the xaml: <Menu Height="21" Margin="0,-2,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"> ...

Best way to create a ViewModel in MVVM

Assume I have a class called Customer. Now I need to render the customer on view. So I created CustomerViewModel to use in binding. I am looking for the best way to create the CustomerViewModel class. Following are my thoughts on creating it. 1 - Create all the properties in the customer again on the view model. Inject the customer inst...

WPF / MVVM - Where do the ViewModels go?

I am kind of new to the whole MVVM pattern, and am trying to wrap my head around it. What I am currently trying to figure out is: in a well structured solution where do the ViewModels live? Currently my design looks something like this (sort of): Application (The view) DomainSpecificCode (ClassLibrary) Gateways (ClassLibrary) If ...

WPF filter combobox items based on ListView items

I'm creating a WPF application using the MVVM design pattern that consists of a ListView and some ComboBoxes. The ComboBoxes are used to filter the ListView. What I am trying to accomplish is populating the combobox with items in the related ListView column. In other words, if my ListView has Column1, Column2, and Column3, I want Comb...

WPF Maintain ListBox selection when tab changes

I have a TabControl where the content of each TabItem is a master-details view. For the master, I'm using a listbox whose ItemsSource is bound to a collection in my ViewModel. Selecting an item from the list displays that particular item's details in a grid off to the side. When I switch to another tab and then back to the original t...

M-V-VM WPF: Way to maintain Databinding while passing parent object of Databound object into IValueConverter?

I'm using model-view-viewmodel I currently have a class with 3 pieces of data: 2 integers and an enumeration. Its constructor looks like this: //C# public Outcome(OutcomeEnum outcomeEnum, Int32 acutalOutcomeData, Int32 expectedOutcomeData) { m_outcomeEnum = outcomeEnum; m_actualData = acutalOutcomeData; m_expectedData = expected...

In WPF, how to databind to the Window DataContext from inside the DataTemplate of a contained ListBox?

I have a WPF Window with a view model set as its DataContext, and have a ListBox with a DataTemplate and its ItemsSource bound to the view model, like in the following example: View model: using System.Collections.Generic; namespace Example { class Member { public string Name { get; set; } public int Age { get; set; } } ...

Is passing a L2S DataContext into a ViewModel constructor clean MVVM?

In my main Window1.xaml.cs, I build an ObservableCollection of ViewModels like this by instantiating with a LINQ-to-SQL model object: using (var db = Datasource.GetContext()) { var customers = from c in db.Customers select c; foreach (var customer in customers) { CustomerCollection.Add(new Custom...

Screen synchronization - Event Aggregator VS Caching ViewModel References...

Hi, i did some homework and couldn't find any article about best practices about when to use each method.. just for clarification: When using the event aggregator pattern : each screen has it's own reference of a viewmodel, the viewmodel publish changes using the eventaggregator, which later the observers use to synchronize their state....

MVVM and events

To keep code out of the view when using the Model-View-View Model pattern (aka Presentation Model), I can expose commands as properties in the view model and bind to those commands from the view. This way my views can be entirely written XAML and no code-behind, other than the mandatory constructor call to InitializeComponent(). This wo...

Databinding with INotifyPropertyChanged instead of DependencyProperties

I have been wrestling with getting databinding to work in WPF for a little over a week. I did get valuable help here regarding the DataContext, and I did get databinding to work via DependencyProperties. While I was learning about databinding, I came across numerous discussions about INotifyPropertyChanged and how it is better than DPs...