mvvm

What is the best way for the ViewModel to manipulate the View?

I understand that in the MVVM pattern, that a ViewModel should know nothing about the View. So there seems to be two ways that the ViewModel can cause something particular to happen on the UI, consider this common flow of events: user types something in a textbox user clicks button button calls DelegateCommand called "Save" on viewmod...

Building a MVVM 3D Editor Application -> Getting Mouse Position?

Hi, In my 3d editor application, I want to be able to click on and move a scene's entities (meshes, lights, cameras, etc). To do that, I imagine that I need to get the current mouse position relative to my Direct3d view and somehow give it to my ViewModel. How would I go about doing that, considering that my app is built with the MVVM p...

How can I handle a Validation.Error in my ViewModel instead of my View's code behind?

I'm trying to get WPF validation to work within the MVVM pattern. In my View, I can validate a TextBox like this which gets handled by the code-behind method "HandleError", which works fine: <TextBox Width="200" Validation.Error="HandleError"> <TextBox.Text> <Binding Path="FirstName" NotifyOnValidation...

When does it make sense to abandon MVVM?

As I've been learning WPF, I've been concentrating on applying only the MVVM pattern to applications. However, I notice that for some functionality such as validation, it is difficult or impossible to remain true to the MVVM model. Many times simply sticking an x:Name on an element and changing it in code-behind event-handler solves the...

MVVM Tabcontrol change tab

I am developing an mvvm app with wpf. A requirement just got added on to block the user from changing tabs if a textbox has text. What is the best way to do this completely in the viewmodel? I don't know how to block a tabitem because there is no dependencyobject command in the tabcontrol to tie into, do i need to roll my own tabcontro...

Is a DelegateCommand the same as an "Attached Behavior"?

I have been using the DelegateCommand found in the MVVM Visual Studio template at CodePlex. This works very nicely for having Views be able to execute commands on their ViewModel. I read somewhere that in MVVM "attached behaviors" should be used. As far as I can tell, "attached behaviors" are the same type of pattern as DelegateCommand ...

What exactly are "WPF services"?

Someone told me in an answer to a stackoverflow question that the "two big guns" for the MVVM pattern are 1) attached behaviors and 2) services. I assume he means "WPF services" a phrase which I found used in the following ways: PresentationFoundation.dll defines the WPF controls types, animation and multimedia support, data bindin...

How to use AttachedCommandBehavior in a new project?

I've downloaded this AttachedCommandProject and ran it and it works well, enables me to e.g. put a MouseDown command on a Border element and handle that with a command in my ViewModel. Now I would like to add this AttachedCommand functionality to my MVVM Visual Studio Template. I copied all the necessary files into the my Commands fold...

How can I attach two attached behaviors to one XAML element?

I've implemented the attached command behavior pattern found here and it works well to allow e.g. a Border to have a left- or right-click event that fires in the ViewModel: XAML: <Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" c:CommandBehavior.Event="MouseLeftButtonDown" c:Comman...

MVVM ICommand alternative

I have begun creating a wpf mvvm app. It seems a vital ingredient to the ViewModel is a bunch of ICommands to have a loosely coupled way of allowing the view to interact with the viewmodel. My question is this, why can't I bind directly to a method? I have used Josh Smith's RelayCommand implementation of ICommand that allows you to in...

How to make a TreeView's and ListBox's SelectedItem stay in sync?

Hi, I'm certain this has come up before, but I haven't been able to find the answer. I made a basic ViewModel that contains a list of People (an array of Person) with a property called SelectedPerson, which naturally points to the currently selected Person in the list of People. I also have a ListBox and a TreeView that are databound t...

MVVM Experts need your opinion on MVVM and Dataforms

Hi, as far as I understand the ViewModel should abstract the model from the view and add additional logic to handle the presentation stuff. My question is: How would I create a dataform that is suppose to handle user input for an order and details at once. It should present fields for entering the orders as well as the fields for 1 de...

How to give focus to and select text in a TextBox from ViewModel

I'm experimenting with MVVM in the context of a simple WPF app. I have a Command attached to a button. If the text in a TextBox is 'incorrect', I want the TextBox to get focus and all it's contents selected. It seems the only way to do this is either through some kind of direct call from the Command in my ViewModel to the View, or set...

Best practice for parent/child-viewmodel-relationships in MVVM using Onyx?

Hy guys! I am currently working on a little WPF project using MVVM via the Onyx framework. My currentview architecture is like this: <DockPanel> <Menu DockPanel.Dock="Top" Background="#cecece"> <!-- Menu --> </Menu> <Grid> <views:TranslationView x:Name="translationView" /> </Grid> </DockPanel> ...

Binding Commands to Events?

Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a pure XAML solution. Thanks! ...

Does anyone have code examples of the WPF Datagrid working in a MVVM pattern?

I got the following example of a WPF DataGrid bound to a ViewModel in a MVVM pattern, but it is read-only: MVVM example which has buttons that switch the data in the ViewModel I tried to extend it so that the DataGrid was bound to an observable collection of ViewModels so that editing cells would fire OnPropertyChanged events on the ap...

WPF Databinding intellisense

Ok, so I have a general question about WPF. I've messed a little with ASP.NET MVC and in the markup it has intellisense on your viewmodel object so you don't mistype it( i love it). Enter WPF, I love it, I'm utilizing the MVVM approach and one annoying thing that I have to do is make sure I'm binding correctly to my viewmodel. So I type...

How do you handle a ComboBox SelectionChanged in MVVM?

For those doing pure MVVM, how do you handle a ComboBox SelectionChanged event without reverting to code behind? I tried e.g. AttachedBehaviors but Event="SelectedChanged" is not supported: <ComboBox> <ComboBoxItem Content="Test1"> <c:CommandBehaviorCollection.Behaviors> <c:BehaviorBinding Event="SelectionChange...

Why are events and commands in MVVM so unsupported by WPF / Visual Studio?

When creating an WPF application with the MVVM pattern, it seems I have to gather the necessary tools myself to even begin the most rudimentary event handling, e.g. AttachedBehaviors I get from here DelegateCommands I get from here Now I'm looking for some way to handle the ItemSelected event in a ComboBox and am getting suggestions...

Why does DelegateCommand not work the same for Button and MenuItem?

This code shows that the Delegate Command from the Visual Studio MVVM template works differently when used with MenuItem and Button: with Button, the command method has access to changed OnPropertyChanged values on the ViewModel when using MenuItem, however, the command method does not have access to changed OnPropertyChanged values ...