mvvm

WPF MVVM Button Control Binding in DataTemplate

I've seen other questions that deal with this, but never any explicit code describing the fix. I can't get a button inside of my ItemTemplate to bind to ANY command anywhere. Very frustrating. I am a complete MVVM newbie, btw. Here's my Window XAML. <Window x:Class="RET.CMS.Printing.App.MainWindow" xmlns="http://schemas.microsoft.c...

WPF, MVVM and Prism modularity

I am still learning to use MVVM and Prism and have some general questions: I have a grid in my view. Lets say I have a button that when I click I want it to auto size the grid columns. Where would that code go? Resizing grid columns is a view thing and the view model shouldn't know about it. So in this case would I be adding the bu...

Returning ad-hoc view models from ASP.NET MVC2 Controllers

Hello - I'm porting an existing system to ASP.NET MVC2. In the current legacy app, the user can select from dozens of available fields to customize CRUD forms for different entities in the domain model, similar to the way ERP systems allow customization of core modules. My question: I'm looking for a good pattern or example for this ki...

How to add a new record to database from XamDataGrid

Hi, I am using a XamDataGrid to populate say books. I want to ADD/EDIT/DELETE books from XamDataGrid and the change should reflect in the database. i.e. when I edit the record in XamDataGrid changes should be stored in the database similarly for Add and Delete. Can anyone please give me sample code or explanation how to achieve this? I...

Accessing unity container in view model class

I have a shell which looks like toolbar and defines my main region (a wrap panel). What I need to do is be able to add widgets to the shell and when a widget is clicked, a new window (view) is opened. Below is what I have so far: I created a module class which adds a view to the main region: public class MyModule : IModule { protec...

how to cleanup view model properly?

hello, i have a view model that is used as the data source for my custom control. in the view model's constructor i set up a WMI ManagementEventWatcher and start it. my view model implements IDisposable, so i stop the watcher in the Dispose method. when i embed the custom control into a window, and then close the window to exit the app...

MVVM C# WPF binding mouse double click

i want to copy content of one text box to another text box by clicking the mouse. how do i bind a mouse click event? ...

How do I differentiate between SelectionChanged on load and on user selection?

As an analogy, we've got two Mr Men in a ComboBox: Mr Happy Mr Grumpy I've a property on my ViewModel (using MVVM to an extent, with a SelectionChanged event in the code behind) which I've called IsGrumpy which defaults to false if the Mr Man is happy and true if the Mr Man is grumpy. Obviously! Now, Mr Happy might have had a heavy n...

how to update a user control when event occurs in another user control?

in my window i have tree view and a text block. tree view is bound to a view model. tree nodes are bound to another view model. the tree view model provides a list of top level tree nodes, and the view model for tree nodes provides the list of node children. there is no notion of the currently selected node in the tree in my view models....

Silverlight MVVM advice with 'Composite' Views

Hi I have a DomainView that allows you to select an Entity in my domain. The Entity is displayed in an EntityView within the DomainView. My question is what should the 'DomainViewModel' property be that the EntityView binds to? The Entity, with the View itself wrapping it up in a EntityViewModel and it binds to that? The Entity, usin...

Silverlight 4 MVVM: Unable to Databind ICommand

I have created a Silverlight User Control. The markup is: <StackPanel Grid.Row="4" Grid.Column="0" Orientation="Horizontal" Width="Auto" Margin="5"> <Button Content="OK" Margin="0,0,5,5" MinWidth="50" Command="{Binding OKCommand}" /> </StackPanel> The code behind declares a Dependency property 'OKCommand' as: public ICommand OKC...

Using roles/permission to enable/disable content in the view

I'm working on an WPF application using the mvvm-light framework. I'm new to both of these. I have a form that allows a user to edit a record in a database. Admin users need to be able to update a field that should be read-only for other users. It would be easy for me to put this enable/disable code in the view's code-behind but my und...

Silverlight 4 Treeview MVVM WCF

I'm having an issue with the treeview control from the silverlight 4 toolkit. I can't get it to view to display my data correctly, the toplevel items are shown but the childnodes are nowhere to be seen. More info: I have a wcf service that delivers a list of Categories with nested subcategories to my viewmodel (I made sure to explicitly...

Question regarding missing RemoveHandler in WPF application function

Hi, We have a few scenarios in our WPF/MVVM application where a window is being instanciated and opened within the confines of a method. Very simplistic example: Private Sub subOpenWindow Dim myViewModel = New Viewmodel1 'create viewmodel that Window1 will use as datacontext AddHandler myViewModel.SomeEvent, AddressOf subHandle...

Handling OnLoad (Loaded) in Silverlight Using MVVM Model

I am new to Silverlight (version 4) and MVVM, and I can't seem to figure out how to bind a command in the XAML to my ViewModel for the "Loaded" event of a UserControl. I can bind a command to a button like this... <Button Command="{Binding ShowImageClick}" /> And it works fine. But I have no idea how to do something similiar onload...

MVVM Foundation: How to close Application Window from ViewModel

I am using MVVM Foundation but I think its quite straight-forward and not really framework specific. My setup is as follows: StartViewModel - has a ExitCommand that returns a RelayCommand/ICommand public ICommand ExitCommand { get { return _exitCommand ?? (_exitCommand = new RelayCommand(() => MessageBox.Show("Hello World"))); } }...

MVVM Foundation: Why return ICommand when its defined as RelayCommand

i am using the SampleModel project from MVVM Foundation.Why is ICommand returned when _decrementCommand is declared as RelayCommand. I know RelayCommand inherits ICommand but won't is be clearer to just return a RelayCommand? public ICommand DecrementCommand { get { return _decrementCommand ?? (_decrementCommand = new RelayCommand(...

MVVM Foundation: Assertion Failed Error: Invalid Property Name

i am just getting started with MVVM Foundation. I am getting my codes below: StartViewModel class StartViewModel : ObservableObject { public StartViewModel() { _counter = 0; } public ICommand IncrementCommand { get { return _incrementCommand ?? (_incrementCommand = new RelayCommand(() => ++Counter)...

How can I sort a bound ListBox with custom sort logic?

I'd like to sort it from the View instead of in the ViewModel. Every example I've seen uses a SortDescription, but it's not customizable. ...

MVVM and Login Windows

I'm writing my first "real" MVVM application, and the first step the user will need to take is to provide login credentials. In the past, I would have shown the login dialog after the main window has been laid out and made visible for the first time. What is the preferred way of doing this in the MVVM world, and why? I see many option...