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

  • Home
  • SEARCH
  • 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 8779127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:42:24+00:00 2026-06-13T19:42:24+00:00

In trying to follow MVVM with WPF I ran across a case where I

  • 0

In trying to follow MVVM with WPF I ran across a case where I am not sure where to put code for testing. All lines in the btnReset_Click Method UI commands so I don’t know if they belong in the view model but I also don’t want to put code in my code behind. I have listed out two options I have thought of but am also open to another solution as well.

Public class  Main : Window
    {
      private void btnReset_Click(object sender, RoutedEventArgs e)
            {
                DynamicStackPanel.Children.Clear();
                controls.Clear();
                txtUsername.Text = string.Empty;
                txtPassword.Text = string.Empty;
                txtResponse.Text = string.Empty;
                cbxTestEnvironment.SelectedValue = string.Empty;
                cbxOperation.SelectedItem = null;
                cbxTestEnvironment.SelectedItem = null;
            }
    }

or

public class MainViewModel : DependencyObject
    {

    public MainViewModel : DependancyObject
    {
          public MainViewModel(UtilityMain win)
        {
          win.btnReset.Click +=btnReset_Click;

        }



 private void btnReset_Click(object sender, RoutedEventArgs e)
        {
            DynamicStackPanel.Children.Clear();
            controls.Clear();
            txtUsername.Text = string.Empty;
            txtPassword.Text = string.Empty;
            txtResponse.Text = string.Empty;
            cbxTestEnvironment.SelectedValue = string.Empty;
            cbxOperation.SelectedItem = null;
            cbxTestEnvironment.SelectedItem = null;
        }
}
  • 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-13T19:42:25+00:00Added an answer on June 13, 2026 at 7:42 pm

    This is not really an MVVM approach. The view model should not contain any references to the view however it should represent the the views logic. Likewise the view should contain as little view logic as possible. You should be able to achieve this separation by using a combination of data and command binding. Bind controls in your view to data properties of the view model. Bind to commands on the view model from the view to invoke view logic. The view model operates on the data not UI controls. The ui controls are updated from the view model via data binding. The whole point is to separate your UI controls from your view logic.

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

Sidebar

Related Questions

Trying to follow the guide here, but it's not working as expected. I'm sure
First some background: I'm working on an application and I'm trying to follow MVVM
I'm trying to follow the steps to compile some C code to import into
I'll start out by saying that I'm trying to follow MVVM as strictly as
I'm trying to follow this MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior tutorial.
Trying to follow some basic examples and getting stuck by this code that is
I have a WPF application that mostly follows MVVM, which I am trying to
I am trying to populate a treeview using mvvm but the tree does not
trying to follow this tutorial http://www.codeguru.com/csharp/csharp/net30/article.php/c15489 I'm not able to select the sql server
I'm trying to follow the MVVM design paradigm with C# and XAML. I'm running

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.