Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:32:20+00:00 2026-06-05T00:32:20+00:00

Does using MVVM model in WPF restricts the programmer from writing code behind? Avoiding

  • 0

Does using MVVM model in WPF restricts the programmer from writing code behind? Avoiding Code behind results in lot of complications but on the other hand coupling rises as an issue. So what is better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:32:22+00:00Added an answer on June 5, 2026 at 12:32 am

    The MVVM model does NOT restrict you from writing code behind.

    What it does promote is that the View should only be dependent on the ViewModel (and the ViewModel on the Model)

    So if you write code behind that is actually implementing the ViewModel you are creating a dependency from the ViewModel to the View.

    Code behind that ONLY does View related things is OK

    The thing you are losing when using code behind is the easy (unit)testing of that code.

    EDIT

    A common expression in MVVM-world is “XAML only”. As much as I like a short, snappy statement it tends to divert from the actual problem MVVM is trying to solve and how it tries to solve it.

    As long as you stick to making the View dependent on the ViewModel and the ViewModel on the Model AND strive for (unit)testability you are on the right track.

    EDIT 2

    In the View handling an event should only do two things: change the View itself or notify the ViewModel using a binding that something has changed. Notifying the VIEW of a change in the ViewModel should be done by implementing INotifyPropertyChanged on the ViewModel.

    In a similar way the ViewModel can respond to events in the View by binding ViewModel Commands to the View.

    A WPF Button has a Command property that can be used. It is executed when the button is clicked.

    If a control has no Command property or you want to execute a command when a different event is raised all you have to do is turn the event into the execution of an ICommand.

    Microsoft already provided an implementation of that in the Blend SDK. From this article:

    ... xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity..."
    <Slider
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="ValueChanged">
                <i:InvokeCommandAction Command="{Binding MyCommand}"
                                       CommandParameter="{Binding Text, ElementName=textBox}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Slider>
    

    And a discussion about commands versus event triggers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started learning WPF MVVM using Prism and Unity. Decoupling the view from
I forked from thread When using MVVM pattern, should code relating to property changes
Does anyone know why using-declarations don't seem to work for importing type names from
I am using MVVM Light toolkit in my WPF application. I would like to
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
I am using MVVM pattern to implement a WPF App. My question is, I
I've got this Silverlight Prism application that is using MVVM. The model calls a
I am trying to populate a treeview using mvvm but the tree does not
In my WPF MVVM application my model is a complex tree of Model objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.