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 8530593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:17:05+00:00 2026-06-11T09:17:05+00:00

I have a form in a window which is opened to add a new

  • 0

I have a form in a window which is opened to add a new instance of an entity. To later edit this entity, what is the best way to present the same form, except with the fields pre-populated?

Without a dirty hack (along the lines of setting a state [add/edit]) and violation of the single responsibility principle, I’m finding it hard to reuse the same view and view model. I’m currently thinking of inheriting from a base view model which contains all the duplicate VM code, but then I’m still stuck with 2 versions of an identical form. What’s the best way to do this whilst keeping it DRY?

I’m reasonably new to WPF, and I’m using the MVVM Light framework.

  • 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-11T09:17:06+00:00Added an answer on June 11, 2026 at 9:17 am

    Use Automapper, it will basically make mapping between your entities and view models painless. Retrieve the entity in question, and map it to a view model to display on your form. You can either create a new view model and bind it to your view, or just re-use the same view model as long as you clear existing fields.

    I would recommend having a state on your view model telling your UI whether you’re in ‘create’ or ‘edit’ mode. In my mind this doesn’t violate single responsibility; the view model is telling the UI how it should display itself. The actual edit and create functionality should be included in separate Command objects.

    http://automapper.org/

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

Sidebar

Related Questions

I have one combobox on the window form and I have one method which
I have a pop up window which lists images using a form and radio
So I have this javascript code onclick of button for a child window which
I have one page which enable user to choose something in a new window:
I have a form inside a window which can be resized. Now, if the
I have a windows-form which runs without any problem and displayed well. But if
I have a form created in Windows Forms which is draggable wherever I click.
I have a form MainForm which is a Windows Forms form that contains many
I have a jQuery Model windows which contains a form. On creating of the
I have a windows form app, and a class which is called Game. Let's

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.