mvvm

WPF Prism deactivate ?

Hi all, I have an problem and would like to know if it is common problem or jsut with me. I am using Wpf with Prism and Unity, all with the pattern MvvM. I am loading a viewModel that has a reference to a dropdown with few items, my idea is that each time that the user click in some place to open the view that has this dropdown is that...

What types of objects should the ViewModel reference in the MVVM pattern?

I've seen quite a few examples of MVVM. I can see that the View should reference the ViewModel. I've seen recently an example of a ViewModel referencing a View, which seems wrong to me, as it would result in tighter coupling. Given that ViewModel is often described as an intermediary between the View and the Model, is there more to the V...

WPF/MVVM: Sync scrolling of two datagrids in different views

I have two datagrids side by side bound to different data tables and each with their own view. The datatables both have the same number of rows, and I want both grids to maintain the same scroll position. I am having trouble finding a way to do this using MVVM... anyone have any ideas? Thanks! -Steven ...

Validation.HasError attached property

Did I miss something? 1- Style <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Validation.HasError}" Value="true"> <Setter Property="BorderBrush" Value="Blue" /> </DataTrigger> </Style.Triggers> <Setter Property="MinWidth" Value=...

Is there an MVVM-friendly way to swap views without value converters firing unnecessarily?

I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing ...

Cannot seem to communicate between views

Hi all I have written a MVVM prototype as a learning exercise and I am struggling to understand how I can communicate between views.Let me explain I have a treeview on the left (leftSideView) ListView on the right (rightSideView) MainWindow (includes the 2 views mentioned above and a splitter) What I have implemented does not work a...

WPF MVVM - Correct way to consume a web service asynchronously

I have implemented MVVM in my WPF application. I was wondering what is the correct way to consume a Web Service from WPF MVVM app. So far, I have created a DataAccess interface and a class that implements this interface. This would serve as a facade / proxy to the web service. The ViewModel gets a reference to this class as the constru...

Pass view to viewmodel with datatemplate

I have a window named ParameterEditorView with a ParameterEditorViewModel as DataContext. In the ParameterEditorViewModel I have a list of ParameterViewModel. In the ParameterEditorView I have an ItemsControl whose ItemsSource is binded to the list of ParameterViewModel in the ParameterEditorViewModel. I need the ParameterViewModel to ha...

MVVM: how to set the datacontext of a user control

Hi, I'm writing an application in WPF, using the MVVm toolkit and have problems with hooking up the viewmodel and view. The model is created with ado.net entity framework. The viewmodel: public class CustomerViewModel { private Models.Customer customer; //constructor private ObservableCollection<Models.Cust...

DataGrid row and MVVM

Hi, I have a wpf datagrid with many rows, each row has some specific behaviors like selection changed of column 1 combo will filter column 2 combo, and what is selected in row 1 column 1 combo cannot be selected in row 2 column 1 combo, etc... So I am thinking of having a view model for the main datagrid, and another for each row. Is ...

How to get dynamic value from View in ViewModel?

I am coming across a scenario where I need to do something in the viewmodel according to the current selection in the view, but according to MVVM, the view model should not know about the existence of view, then how can i get the dynamic selection in the view? ...

MVVM: where is the best place to integrate an id counter, in ViewModel or Repository or... ?

Hello, I am using http://loungerepo.codeplex.com/ this library needs a unique id when I persist my entities to the repository. I decided for integer not Guid. The question is now where do I retrieve a new integer and how do I do it? This is my current approach in the SchoolclassAdministrationViewModel.cs: public SchoolclassAdminist...

MVVM,WPF: How to set a item as selected in a combobox

It seems nobody has yet found a way to set the comboboxitem as selected with a SelectedItem="Binding Property". Is the solution to use a IsSelected Property in the ViewModel object within the combobox itemssource ? ...

M-V-VM best practices

I found two ways to use M-V-VM pattern in WPF: allocate the ViewModel into the View's code behind (setting it as the DataContext); allocate the ViewModel into a XAML file and create the corresponding view using a DataTemplate. The Model can be allocated into the ViewModel's constructor. What do you think about this way of using M-V-...

Binding command to button in silverlight 4 using mvvm

Hello, I have a user control called HomePage.xaml. I'm creating a model instance (using MVVM pattern) in the code behind file in the constructor of page as MainViewModel model = new MainViewModel(); I have a button in HomePage.xaml which I want to bind to the command inside MainViewModel called GetData() and want to populate the data...

WPF SelectedItem not working in MVVM

Hi, I'm trying to display the data from two sql ce 3.5 sp1 database tables linked with foreign key - Customers and Orders. When the customer is selected in a datadrig, I want the other grid to be populated with the Orders. I'm using a query: var profiles = from c in db.Customers.Include("Orders") select c; A...

Data binding manually update in WPF MVVM

My ViewModel: class ViewModel { public string FileName {get;set;} } and in my View I bind a label's content to ViewModel's FileName. now When I do drag-drop a file to my View, How can I update the label's Content property, so that the ViewMode's FileName also get updated via binding? Directly set the label's Content property won't w...

WPF databinding update comboxbox2 based on selection change in combobox1 with MVVM

I have a combo box that I have bound to a list that exists in my viewmodel. Now when a users makes a selection in that combo box I want a second combo box to update its content. So, for example, combobox1 is States and combobox2 should contain only the Zipcodes of that state. But in my case I don't have a predefined lists before hand ...

What do you name the "other" kind of view-model in an MVVM project?

With MVVM, I think of a view-model as a class that provides all the data and commands that a view needs to bind to. But what happens when I have a database entity object, say a Customer, and I want to build a class that shapes or flattens the Customer class for use in a data grid. For example, maybe this special Customer object would ha...

how to load wpf usercontrol in MVVM pattern

Hi, I'm creating a wpf user control which is in mvvm pattern. So we have : view(with no code in codebehind file), viewmodel,model,dataaccess files. I have MainWindow.xaml as a view file, which I need to bind with MainWindowModel.cs. Usually, in a a wpf application we can do this with onStartUp event in App.xaml file. But in user contr...