mvvm

How to copy data from different classes by matching field or property names

I am looking to find a way to take two objects that have identical properties and make a call to copy the property values from one object into the other. The the example below assume I have an instance of A and I want to use the data of that instance to hydrate a new instance or C (to keep things terse I used fields instead of properties...

Confusion over IRepository

I'm a bit confused about when using the "IRepository pattern", when actually to load the data. Currently I have something like this: public class MainViewModel : ViewModelBase { // EF4 generated ObjectContext private ScorBotEntities context = new ScorBotEntities(); // Custom IUserRepository class private IUse...

Adding to a collection in MVVM

Hi all, I have 2 ViewModels. One is called User (containing basic information, nothing fancy) and another called Group, which has as a property, an IEnumerable of User. This IEnumerable is backed by a dictionary (there are a lot of users, need to search them fast) public class Group { #region Fields private Dictionary<string, Us...

Update Dependency Property prior to program exit

I have created a dependency property of type Binary on a RichTextBox which allows me to bind to a FlowDocument which is in binary form (byte[]) within the ViewModel. This works well, the property converts to and back correctly. Whenever the RichTextBox looses focus then the value of the dependency property is updated with the new binary...

Do we need to unit test the GUI when using proper abstraction?

With a good design pattern like MVP, MVC, etc we aim to move all logic out of the GUI. That leaves us with a light weight GUI which ideally just need to "bind" its buttons and fields to properties in some business logic layer. This is a great approach as this layer will be free from GUI stuff, and we can easily write unit tests for it. ...

Pass an object between ViewModels in Silverlight

i have a ViewModel that have a Method to receive a Func<Uri,bool> for navigation and a button that i implement ICommand which execute that method(i instantiate ViewModel in Code behind and pass Navigate of Frame to that). i navigate between pages properly but there is a no idea to pass an object(e.g Person) to another page because ther...

Calling a Method of a UserControl in MVVM

I'm having an issue with calling a method on a UserControl. Hear me out: I have a UserControl someControl in SomeView.xaml SomeView.xaml's DataContext is SomeViewModel.cs I want to be able to call someControl.DoStuff() somehow, somewhere. DoStuff is not UI specific (I could have just called DoStuff from the code-behind of SomeView.Xaml...

MVVM WPF: Reflecting a controls property to the viewmodel, when an events get triggered.

Okay i'm trying to understand WPF and the popular MVVM Pattern. Now i have this issue. I'm using a ribbon control with several tabs. In my ViewModel i have a property "ActiveTab (string)" Which should reflect the currently active tab. Since ribboncontrol doesn't have any property that shows this information i can't bind to it. So i wa...

Binding multiple ViewModels to Content Control on each command

Hi, I have gone through the example of the Tab Control to hold multiple views. But my requirement is bit different. The content control should be the only region to show the views and it must change according to the Commands for example: Add New, View All, Search, etc.. Thanks in advance. ...

Silverlght 4 TabControl MVVM tab header binding problem

In silverlight app I create tab items dynamically in code (MainView's code-behind): TabItem tab = new TabItem(); CustomerView view = new CustomerView(); view.DataContext = customerViewModel; //or tab.DataContext = customerViewModel;?? tab.Content = view; DataTemplate template = this.Resources["CustomTabItemHeader"] as DataTemplate; tab....

When using MVVM pattern, should code relating to property changes go in the setter or an event?

Looking for guidance on where to place code which is dependent upon changes to a property. For example, I have a view model which is used to hold state for an applications settings public SettingsViewModel(ISettingsRepository settings) { _settings = settings; // ... } For each change to a settings property we have to persist ...

Command Parameter is null in a Command of CustomDataGrid.

This code works fine : <sdk:DataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementNa...

WPF/RibbonGallery: Need help understanding binding and events

i need some help understanding the example posted by Lester's Blog: Using RibbonGallery Control. i am relatively new to WPF and not really familiar with MVVM i dont really understand how the ribbon gallery in the sample is bound and how to handle events like click/selection change to switch the font or color. ...

How can I force my busy indicator to display? (WPF)

I've created a busy indicator - basically an animation of a logo spinning. I've added it to a login window and bound the Visibility property to my viewmodel's BusyIndicatorVisibility property. When I click login, I want the spinner to appear whilst the login happens (it calls a web service to determine whether the login credentials are ...

PropertyChangedEventHandler is null in FirePropertyChanged

Hi, I have a viewmodel named EmployeeViewModel which is inherited from ViewModelBase. here is the implementation of ViewModelBase. public event PropertyChangedEventHandler PropertyChanged; public void FirePropertyChanged(string propertyname) { var handler = PropertyChanged; if (handler != null) ha...

Is there a way to call Navigate from within the ViewModel?

I have a Silverlight 4 project which displays a chart and some buttons to allow the user to change the chart's date range. The date range can also be passed in via a query string parameter - something like http://myserver/MySilverlightPage/#?DateRange=OneMonth - and when the user clicks a button I'd like to update the Url as well. I u...

How to save data from a DetailView bound to a ViewModel if the repository is a no-go in a viewmodel ?

Hello, we mvvm lovers all know Josh Smith mvvm sample and how he has saved the customer in the detail customer view by injecting the repository object into the customerViewModel`s constructor. But a viewmodel should not know about repositories. Its just a model of a view nothing must being aware of persistence etc... How can I registe...

How do I clear the values inserted on save command in MVVM WPF

Hi, I am able to save the data to database using the save command. But the entered data is not cleared after successfully save operation. How do I clear the values in ViewModel itself. Thanks ...

MVVM best practice around view logic in Silverlight

I am trying to get into MVVM and away from the code behind approach in Silverlight, and I want to know the best practices around how to invoke view logic. I have a very basic page where I have bound a listbox to a collection of domain objects, this is all using MVVM, so when I recieve my data back from the services, I want to fire off a...

ContentControl does not show change

Hi, The following code is in a MEF MVVM desktop application. The Shell is already build, but a Module is initialising. The Module wants to add text to a ContentControl in the Shell, but the following code does not cause the change to be seen in the Shell Window. Any suggestions as to how I get the window to update. thanks [Importin...